필터 지우기
필터 지우기

how to find the square of the number

조회 수: 17 (최근 30일)
johnson saldanha
johnson saldanha 2018년 12월 13일
댓글: johnson saldanha 2018년 12월 13일
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