Error using save: Argument must contain a character vector
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Marki Wong
el 24 de Oct. de 2017
Editada: Cam Salzberger
el 8 de Abr. de 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 comentarios
Respuesta aceptada
Cam Salzberger
el 24 de Oct. de 2017
Editada: Cam Salzberger
el 24 de Oct. de 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 comentarios
Sara Salimi
el 8 de Abr. de 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
el 8 de Abr. de 2019
Editada: Cam Salzberger
el 8 de Abr. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!