Borrar filtros
Borrar filtros

how to find the square of the number

17 visualizaciones (últimos 30 días)
johnson saldanha
johnson saldanha el 13 de Dic. de 2018
Comentada: johnson saldanha el 13 de Dic. de 2018
i have a matrix x where x(:,3)=[ 2 3 4 5 6];
i want the output as y(:,1)=[ 6 16 40 96 ];
input and output should be column vectors. ignoring the first element of input. i want the input to be multiplied with the (row number)^i. where i=1:length(x-1)
the code i tried is below
y=[];
for i=1:(size(x)-1)
y(i,1)= i^2*(x(2:length(x),3));
end
im getting the error as dimensions mistached, could u help me out

Respuesta aceptada

per isakson
per isakson el 13 de Dic. de 2018
Editada: per isakson el 13 de Dic. de 2018
This produces something that is close to the result you want
%%
x(:,3)=[2;3;4;5;6];
len = size(x,1);
y = nan( len-1, 1 );
for ii = 1:len-1
y(ii,1)= ii^2*x(ii+1,3);
end
Obviously, I'm missing something in your description

Más respuestas (0)

Categorías

Más información sobre Logical 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!

Translated by