Storing values from for loop in array and calling functions
显示 更早的评论
I am writing a function to run an m file multiple times and place all outputs into a matrix named AllSimData. I have a few issues. When I run the code below as is, the output is just the pre-allocated zeros matrix. If I try to have line 10 be AllSimData(ii,:)=MakeFakeData(n); the error is "Subscripted assignment dimension mismatch." I'm not sure how to proceed, as I am new to programming.
function [AllSimData] = catSim( SimNumber,n )
%This function will run MakeFakeData(n)the number of times specified as the
%value of SimNumber. Each output of MakeFakeData is a nx5 matrix. This
%function will concatenate each nx5 matrix vertically, creating a huge nx5
%matrix to represent multiple simulations of data generation.
AllSimData=zeros(10000,5);
for ii=1:SimNumber
MakeFakeData(n); %n=number of data points/rows in each FakeData set
AllSimData(ii,:); %Run through all specified iterations of MakeFakeData and add them to array AllSimData.
end
end
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!