How can I concatenate two string vectors 5x1 and 1x18 to get a 5x18 text matrix
1 view (last 30 days)
Show older comments
Christopher Mahoney
on 1 Aug 2017
Edited: Andrei Bobrov
on 1 Aug 2017
the vectors include Currencies =["ARS","BRL","CLP","COP","CZK","HUF","IDR","MXN","MYR","PEN","PHP","PLN","RON","RUB","ZAR","THB","TRY"] the 1x18 vector and Criteria = ["TR";"YC";"SPR";"SS"] the 5x18 vector, goal is to concatenate so that cell (1,1) of the 5x18 matrix equals "ARSTR", cell (2,2) = "BRLYC" etc.
0 Comments
Accepted Answer
More Answers (1)
Andrei Bobrov
on 1 Aug 2017
Edited: Andrei Bobrov
on 1 Aug 2017
In R2016b:
>> Currencies = {'ARS','BRL','CLP','COP','CZK','HUF','IDR','MXN','MYR','PEN','PHP','PLN','RON','RUB','ZAR','THB','TRY'};
Criteria = {'TR';'YC';'SPR';'SS'};
out = string(Currencies) + string(Criteria)
out =
4×17 string array
Columns 1 through 7
"ARSTR" "BRLTR" "CLPTR" "COPTR" "CZKTR" "HUFTR" "IDRTR"
"ARSYC" "BRLYC" "CLPYC" "COPYC" "CZKYC" "HUFYC" "IDRYC"
"ARSSPR" "BRLSPR" "CLPSPR" "COPSPR" "CZKSPR" "HUFSPR" "IDRSPR"
"ARSSS" "BRLSS" "CLPSS" "COPSS" "CZKSS" "HUFSS" "IDRSS"
Columns 8 through 14
"MXNTR" "MYRTR" "PENTR" "PHPTR" "PLNTR" "RONTR" "RUBTR"
"MXNYC" "MYRYC" "PENYC" "PHPYC" "PLNYC" "RONYC" "RUBYC"
"MXNSPR" "MYRSPR" "PENSPR" "PHPSPR" "PLNSPR" "RONSPR" "RUBSPR"
"MXNSS" "MYRSS" "PENSS" "PHPSS" "PLNSS" "RONSS" "RUBSS"
Columns 15 through 17
"ZARTR" "THBTR" "TRYTR"
"ZARYC" "THBYC" "TRYYC"
"ZARSPR" "THBSPR" "TRYSPR"
"ZARSS" "THBSS" "TRYSS"
>>
In R2017a:
>> Currencies =["ARS","BRL","CLP","COP","CZK","HUF","IDR","MXN","MYR","PEN","PHP","PLN","RON","RUB","ZAR","THB","TRY"];
Criteria = ["TR";"YC";"SPR";"SS"];
out = Currencies + Criteria
out =
4×17 string array
Columns 1 through 8
"ARSTR" "BRLTR" "CLPTR" "COPTR" "CZKTR" "HUFTR" "IDRTR" "MXNTR"
"ARSYC" "BRLYC" "CLPYC" "COPYC" "CZKYC" "HUFYC" "IDRYC" "MXNYC"
"ARSSPR" "BRLSPR" "CLPSPR" "COPSPR" "CZKSPR" "HUFSPR" "IDRSPR" "MXNSPR"
"ARSSS" "BRLSS" "CLPSS" "COPSS" "CZKSS" "HUFSS" "IDRSS" "MXNSS"
Columns 9 through 16
"MYRTR" "PENTR" "PHPTR" "PLNTR" "RONTR" "RUBTR" "ZARTR" "THBTR"
"MYRYC" "PENYC" "PHPYC" "PLNYC" "RONYC" "RUBYC" "ZARYC" "THBYC"
"MYRSPR" "PENSPR" "PHPSPR" "PLNSPR" "RONSPR" "RUBSPR" "ZARSPR" "THBSPR"
"MYRSS" "PENSS" "PHPSS" "PLNSS" "RONSS" "RUBSS" "ZARSS" "THBSS"
Column 17
"TRYTR"
"TRYYC"
"TRYSPR"
"TRYSS"
>>
for older version of the MATLAB:
>> Currencies = {'ARS','BRL','CLP','COP','CZK','HUF','IDR','MXN','MYR','PEN','PHP','PLN','RON','RUB','ZAR','THB','TRY'};
Criteria = {'TR';'YC';'SPR';'SS'};
[ii,jj] = ndgrid(1:numel(Criteria),1:numel(Currencies));
out = cellfun(@(a,b)strcat(a,b),Currencies(jj),Criteria(ii),'un',0)
out =
4×17 cell array
Columns 1 through 11
'ARSTR' 'BRLTR' 'CLPTR' 'COPTR' 'CZKTR' 'HUFTR' 'IDRTR' 'MXNTR' 'MYRTR' 'PENTR' 'PHPTR'
'ARSYC' 'BRLYC' 'CLPYC' 'COPYC' 'CZKYC' 'HUFYC' 'IDRYC' 'MXNYC' 'MYRYC' 'PENYC' 'PHPYC'
'ARSSPR' 'BRLSPR' 'CLPSPR' 'COPSPR' 'CZKSPR' 'HUFSPR' 'IDRSPR' 'MXNSPR' 'MYRSPR' 'PENSPR' 'PHPSPR'
'ARSSS' 'BRLSS' 'CLPSS' 'COPSS' 'CZKSS' 'HUFSS' 'IDRSS' 'MXNSS' 'MYRSS' 'PENSS' 'PHPSS'
Columns 12 through 17
'PLNTR' 'RONTR' 'RUBTR' 'ZARTR' 'THBTR' 'TRYTR'
'PLNYC' 'RONYC' 'RUBYC' 'ZARYC' 'THBYC' 'TRYYC'
'PLNSPR' 'RONSPR' 'RUBSPR' 'ZARSPR' 'THBSPR' 'TRYSPR'
'PLNSS' 'RONSS' 'RUBSS' 'ZARSS' 'THBSS' 'TRYSS'
>>
0 Comments
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!