how to find the square of the number

32 次查看(过去 30 天)
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

采纳的回答

per isakson
per isakson 2018-12-13
编辑:per isakson 2018-12-13
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by