Error using save: Argument must contain a character vector
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Marki Wong
le 24 Oct 2017
Modifié(e) : Cam Salzberger
le 8 Avr 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 commentaires
Réponse acceptée
Cam Salzberger
le 24 Oct 2017
Modifié(e) : Cam Salzberger
le 24 Oct 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 commentaires
Sara Salimi
le 8 Avr 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
le 8 Avr 2019
Modifié(e) : Cam Salzberger
le 8 Avr 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!