How can I include a repeated word into a matrix?
14 views (last 30 days)
Show older comments
I have 2 matrices that look like this
2016_Subject_
2016_Subject_
2016_Subject_
_01
_02
_03
and I need to put the word 'Speed' in between each line - Expected answer is
2016_Subject_Speed_01
2016_Subject_Speed_02
2016_Subject_Speed_03
this code
[L(i,1:end-2), 'Speed', L(i,end-2:end),]
where L is ls(targetfolder) ie. a list of the subfolders in a main folder and looks like
2016_Subject_01
2016_Subject_02
2016_Subject_03
doesn't work and comes up with the error
"Error using horzcat Dimensions of matrices being concatenated are not consistent."
which is only due to the inclusion of the words.
Any ideas how to overcome this?
Thanks in advance
3 Comments
Azzi Abdelmalek
on 7 Jul 2016
Edited: Azzi Abdelmalek
on 7 Jul 2016
You can post the expected result, because "put the word 'Speed' in between each line" is not clear
Stephen23
on 8 Jul 2016
@Eleanor H: it is still not very clear exactly how your data are stored, but you can try experimenting with strcat to achieve what you want:
A = {...
'2016_Subject_'
'2016_Subject_'
'2016_Subject_'};
B = {...
'_01'
'_02'
'_03'};
strcat(A,'Speed',B)
creates this:
ans =
'2016_Subject_Speed_01 '
'2016_Subject_Speed_02'
'2016_Subject_Speed_03'
Answers (2)
Thorsten
on 7 Jul 2016
Edited: Thorsten
on 7 Jul 2016
Use strcat
L1 = ['2016_Subject_'; '2016_Subject_'; '2016_Subject_']
L2 = ['_01'; '_02'; '_03'];
strcat(L1, 'Speed', L2)
It also works with cells
C1 = {'1_Subject_'; '10_Subject_'; '1000_Subject_'};
C2 = {'_01'; '_02'; '_1000'};
strcat(C1, 'Speed', C2)
0 Comments
José-Luis
on 7 Jul 2016
a = repmat('2016_Subject_',3,1);
b = ['_01'; '_02'; '_03'];
your_array = cat(2,a,repmat('Speed',size(a,1),1),b);
0 Comments
See Also
Categories
Find more on Matrix Indexing 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!