Error using save: Argument must contain a character vector
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Marki Wong
am 24 Okt. 2017
Bearbeitet: Cam Salzberger
am 8 Apr. 2019
Can somebody give me some insight on how to fix this? I am super new to MatLab.
load Assignment_4_data
ones_row = ones(1,8);
Q1_1 = [ones_row;Num1;ones_row];
ones_column = ones(10,1);
Q1_2 = [-ones_column, Q1_1, ones_column];
new_row = Q1_2(7,2:9)-2;
Q1_2(7,2:9)= new_row;
data = Q1_2.^2;
save(part_1,'data');
0 Kommentare
Akzeptierte Antwort
Cam Salzberger
am 24 Okt. 2017
Bearbeitet: Cam Salzberger
am 24 Okt. 2017
Hello Marki,
I assume that you are trying to save your data variable to a MAT file entitled part_1.mat?
In that case, you just need to add single-quotes around part_1 to make it a character vector. Currently, MATLAB is trying to access a variable called part_1, which seems to exist (maybe) but doesn't contain character data.
save('part_1', 'data')
save part_1 data
Also, unless your assignment specifies otherwise, you can just do:
Q1_2(7,2:9) = Q1_2(7,2:9)-2;
No need to make a temporary variable.
-Cam
3 Kommentare
Sara Salimi
am 8 Apr. 2019
What if it is a variable containg a text? I have different directory and seed to save for each them separately in a for loop. I am facing with the same error.
fname=strcat(dirnames(i),'.mat');
save(fname,'X_features','Y_label');
Cam Salzberger
am 8 Apr. 2019
Bearbeitet: Cam Salzberger
am 8 Apr. 2019
Sara, that should work fine. Though if dirnames is a cell array of character vectors, you'll need to use dirnames{i}. If it's a string array, then it's correct as is.
Can you show what happens when you do this:
class(dirnames)
size(dirnames)
disp(dirnames)
Maybe at some point, dirnames(i) does not contain text? You could always run this code to go into debug mode when your error is hit, and see what the issue is:
dbstop if error
-Cam
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB 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!