Filter löschen
Filter löschen

Error using "Save" Command.

9 Ansichten (letzte 30 Tage)
Hassan Ashraf
Hassan Ashraf am 28 Jun. 2019
Kommentiert: Hassan Ashraf am 28 Jun. 2019
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

Akzeptierte Antwort

Steven Lord
Steven Lord am 28 Jun. 2019
Bearbeitet: Steven Lord am 28 Jun. 2019
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.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by