简体   繁体   中英

How to store outputs from a function to a matrix in matlab?

so far I have this:

time=(0:15:16*1440);

data=zeros(3,length(time));
for i=1:length(time)
(not sure what goes here)=ValidateTime(0,0,time(i));
end

validateTime is my function that returns 3 values. How would I store the output from the function into the data matrix I created before?

Assuming ValidateTime(..) returns a row vector of length 3, you can transpose it to a column vector and assign in it to the i'th column in your data matrix.

time=(0:15:16*1440);

data=zeros(3,length(time));
for i=1:length(time)
    data(:,i)=ValidateTime(0,0,time(i))';  % Note the single quote!
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM