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

8 views (last 30 days)
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 Comment
Stephen23
Stephen23 on 16 Aug 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'};

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 16 Aug 2018
Edited: Stephen23 on 16 Aug 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.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!