Error using "Save" Command.
9 次查看(过去 30 天)
显示 更早的评论
I am trying to save some files iteratively in a loop anf getting below error. Can someone please help me out?
Error: Error using save
Must be a string scalar or character vector.
names=["CH" , "OH" , "EX" , "FL" , "GR" , "IN" , "SU" , "PR" , "RT"];
fields = fieldnames(U);
fields = fields(5:13);
for j=1:nMotions
for i=1:nChannels
CM=U.(fields{j});
CM=CM(:,i);
ConcatenatedSignal=CM';
flag=1;
for k=1:1:floor(length(ConcatenatedSignal)/nos)
dataA = ConcatenatedSignal(flag:1:nos+flag-1);
save(['C:\Users\AKRA\Desktop\New folder\' names(j),'\channel' num2str(i),'/M_' num2str(k) '.mat'],'dataA');
flag=flag+nos;
end
end
end
0 个评论
采纳的回答
Steven Lord
2019-6-28
编辑:Steven Lord
2019-6-28
Your names variable is a string array. This means names(j) is a string. Compare:
c1 = 'abc';
s1 = string(c1);
c2 = [c1 '123']
s2 = [s1 '123']
c2 is a 1-by-6 char vector that save knows how to handle. s2 is a 1-by-2 string array which is not a scalar, so save doesn't know how to handle it. If you want to build a longer (in terms of strlength) string array from a string and a char or from multiple string arrays, combine them with +. You can even add in numbers and they will be converted into a string.
s3 = 'C:\Users\AKRA\Desktop\New folder\' + s1 + '\channel' + ...
5 + '/M_' + 42 + '.mat'
s4 = s1 + 123
This works as long as at least one of the pieces of text and/or numeric data you're trying to combine is a string. If they're all char or numeric data, you'll need to concatenate with square brackets and convert the numbers to text yourself.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!