Unable to perform assignment because the size of the left side is 2-by-1 and the size of the right side is 1-by-3.
    1 view (last 30 days)
  
       Show older comments
    
Hola, este es mi codigo y me da el error del titulo, las funciones las tengo abiertas en las pestañas de a los lados, alguien puede ayudarme?
clear clc;
reply = input('Introduce el numero de ejercicio que deseas graficar? (1,2,3,4,5): ','s');
if strcmp(reply,'3')
    t=-2:0.01:2;
    x=zeros(2,length(t));
    dx=zeros(2,length(t));
elseif strcmp(reply,'1'&&'2'&&'4'&&'5')
    t=-10:0.001:10;
    x=zeros(3,length(t));
    dx=zeros(3,length(t));
else    
   disp('Ese numero no coincide con ninguna de las opciones,') 
if strcmp(reply,'1')
hold on
    for i=1:length(t)
    x(:,i)=fun1(t(i));
    dx(:,i)=fun1d(t(i));
    end
elseif strcmp(reply,'2')
    hold on
    for i=1:length(t)
    x(:,i)=fun2(t(i));%grafica sin derivar la fucion del ejercicio 1
    dx(:,i)=fun2d(t(i));%grafica la funcion derivada del ejercicio 1
    end
elseif strcmp(reply,'3')
    hold on
    for i=1:length(t)
    x(:,i)=fun3(t(i));
    dx(:,i)=fun3d(t(i));
    end
elseif strcmp(reply,'4')
    hold on
    for i=1:length(t)
    x(:,i)=fun4(t(i));
    dx(:,i)=fun4d(t(i));
    end
elseif strcmp(reply,'5')
    hold on
    for i=1:length(t)
    x(:,i)=fun5(t(i));
    dx(:,i)=fun5d(t(i));
    end
end
end
if strcmp(reply,'3')
    subplot(2,1,1)
    plot(x(1,:),x(2,:))%Con esta imprimimos 2 dimensiones
    title('Grafica de la función vectorial sin derivar')
    xlabel('f(t)')
    ylabel('g(t)')
    grid on
    subplot(2,1,2)
    plot(dx(1,:),dx(2,:))
    title('Grafica de la función vectorial derivada')
    xlabel('df/dt')
    ylabel('dg/dt')
    grid on
elseif strcmp(reply,'1'&&'2'&&'4'&&'5')
    subplot(2,1,1)
    plot3(x(1,:),x(2,:),x(3,:))% con esto imprimos para 3 componentes
    title('Grafica de la función vectorial sin derivar')
    xlabel('f(t)')
    ylabel('g(t)')
    zlabel('h(t)')
    grid on
    subplot(2,1,2)
    plot3(dx(1,:),dx(2,:),dx(3,:))
    title('Grafica de la función vectorial derivada')
    xlabel('df/dt')
    ylabel('dg/dt')
    zlabel('dh/dt')
    grid on
else
   disp('por lo tanto no se creara ninguna grafica, vuelve a intentarlo.')  
end
0 Comments
Answers (1)
  Matt J
      
      
 on 9 Jul 2020
        
      Edited: Matt J
      
      
 on 9 Jul 2020
  
      This error message results from doing something like this:
>> x=rand(2,3);
>> x(:,1)=[4,5,6]
Unable to perform assignment because the size of 
the left side is 2-by-1 and the size of the right side is 1-by-3.
Clearly, this is wrong because the size of x(:,1) is 2x1 and the thing you are trying to assign into it is a different size, 1x3.
3 Comments
  Matt J
      
      
 on 9 Jul 2020
				
      Edited: Matt J
      
      
 on 9 Jul 2020
  
			To tell you how to fix it, you would first have to tell me what  fun5 should return (what is the size of the correct output) and also what the size of x is supposed to be when the code is working correctly. This lines makes it look like the output of funS will always be 1x3,
r=[ft,gt,ht];
wherease x(:,i) can never be 1x3. It will always be a 2x1 or 3x1 column vector.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
