How can I include a repeated word into a matrix?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Azzi Abdelmalek
2016-7-7
编辑:Azzi Abdelmalek
2016-7-7
You can post the expected result, because "put the word 'Speed' in between each line" is not clear
Stephen23
2016-7-8
@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'
回答(2 个)
José-Luis
2016-7-7
a = repmat('2016_Subject_',3,1);
b = ['_01'; '_02'; '_03'];
your_array = cat(2,a,repmat('Speed',size(a,1),1),b);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!