how to find the square of the number
25 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
johnson saldanha
am 13 Dez. 2018
Kommentiert: johnson saldanha
am 13 Dez. 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
0 Kommentare
Akzeptierte Antwort
per isakson
am 13 Dez. 2018
Bearbeitet: per isakson
am 13 Dez. 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!