too many output arguments when calling axis in cellfun
Mostrar comentarios más antiguos
Hi there!
I want to use cellfun to plot figure for each element of the cell C3.
The code is:
cellfun(@(x,i){...
figure(i);...
set(gcf,'Position',[400*(i-1),50,400,300], 'color','w');...
fill(real(x),imag(x),[1,0.75,0],'EdgeColor','None');...
axis(gca,'equal','off')},...
C3,num2cell(1:length(C3)),'UniformOutput',false);
The error occurs: too many output arguments.
The problem come from
axis(gca,'equal','off')
It has no output argument.
So how to use cellfun to plot figure and modify its axis?
I know I could use for loop to plot, but the one-line code is cool.
By the way, code of this form seems difficult to fit into a one line code
axis equal off
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 10 de Abr. de 2023
The code sequence
@(x,i){...
figure(i);...
set(gcf,'Position',[400*(i-1),50,400,300], 'color','w');...
fill(real(x),imag(x),[1,0.75,0],'EdgeColor','None');...
axis(gca,'equal','off')}
is not equivalent to executing the individual functions at the command line or as individual commands. MATLAB does not have "code blocks" like C or C++ does. {A; B} does not mean to designate a series of statements to be executed.
Instead, {} is the cell-array constructor. Each entry is to be evaluated, and the (first) return output from the command is to become the value of the corresponding cell entry. So
{...
figure(i);...
set(gcf,'Position',[400*(i-1),50,400,300], 'color','w');...
fill(real(x),imag(x),[1,0.75,0],'EdgeColor','None');...
axis(gca,'equal','off')}
is like
temp1 = figure(i);
temp2 = set(gcf,'Position',[400*(i-1),50,400,300], 'color','w');
temp3 = fill(real(x),imag(x),[1,0.75,0],'EdgeColor','None');
temp4 = axis(gca,'equal','off');
output = {temp1, temp2, temp3, temp4};
If any of the statements do not (cannot) return a value, then you would get an error.
Categorías
Más información sobre Linear Algebra en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!