hey how can i make column output?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ariela Glikman
am 26 Nov. 2018
Kommentiert: madhan ravi
am 26 Nov. 2018
hey how can i make column output? (and not row vec)
% the function gets a vector of numbers (=vecOfNum)
% and return output vector (=vecPrevMean),
% each element is the average of all previous elements.
function [vecPrevMean]= vecMean(vecOfNum)
count=1; %count the amount of elements in the vector
sumNum=0; %sum the elements
for i=1:length(vecOfNum);
if iscolumn(vecOfNum)==0
sumNum= sumNum+ vecOfNum(i);
vecPrevMean(i)=sumNum./count;
count=count+1;
elseif iscolumn(vecOfNum)==1
sumNum= sumNum+ vecOfNum(i);
vecPrevMean(i)=(sumNum./count)';
count=count+1;
end
end
0 Kommentare
Akzeptierte Antwort
madhan ravi
am 26 Nov. 2018
vecPrevMean(i,1)=(sumNum./count)';
% ^---------change to this (note : preallocation is also important)
1 Kommentar
madhan ravi
am 26 Nov. 2018
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!