Storing values from for loop in array and calling functions
Show older comments
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
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!