openfig has the error 'The value of 'Filename' is invalid. It must satisfy the function: ischar.'

9 visualizzazioni (ultimi 30 giorni)
I am opening figures in a loop but I get error
Error using openFigure
The value of 'Filename' is invalid. It must satisfy the function: ischar.
Error in openfig>localGetFileAndOptions (line 98)
ip.parse(args{:});
Error in openfig (line 37)
[filename, reuse, visibleAction] = localGetFileAndOptions(varargin);
f_range_name = [ {'MI_.5Hz.fig'}, {'MI_.525.fig'}, {'MI_.55.fig'}, ...
{'MI_.575.fig'}, {'MI_.6.fig'}];
for j = 1:length(temp_f)
[~,I]= min(f_range - temp_f(j));
openfig((f_range_name(I)))
hold on
plot(temp_f(j), temp_d(j), temp_k(j), 'o',...
'MarkerEdgeColor','k','MarkerFaceColor', 'b', ...
'MarkerSize', 9)
savefig(['MI_' num2str(f_range(I)) 'Hz.fig'])
close all
end
  1 Commento
Stephen23
Stephen23 il 16 Ago 2018
This is a pointlessly complex way to define a cell array:
f_range_name = [ {'MI_.5Hz.fig'}, {'MI_.525.fig'}, {'MI_.55.fig'}, {'MI_.575.fig'}, {'MI_.6.fig'}];
Simpler:
f_range_name = {'MI_.5Hz.fig', 'MI_.525.fig', 'MI_.55.fig', 'MI_.575.fig', 'MI_.6.fig'};

Accedi per commentare.

Risposta accettata

Stephen23
Stephen23 il 16 Ago 2018
Modificato: Stephen23 il 16 Ago 2018
You used the wrong indexing for the cell array. You need to use curly braces:
openfig((f_range_name{I}))
^ ^ curly braces to access the contents of a cell array!
The difference is simple:
  • {} curly braces access the cell contents.
  • () parentheses access the cells themselves.

Più risposte (0)

Categorie

Scopri di più su File Operations in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by