0

Basically i have a function that returns a column vector of size Z(100,1) of values. I want to run that function in a loop n times, and store each of those column vectors in a seperate index of an array, yet im having trouble doing this. This is my code that matlab does not like...

numSignals = 30;
Z = zeros(1,numSignals);

for n = 1:numSignals

    % load signal of to be reconstructed 
    Z(1,n) = loadSignal(n);

end
0

1 Answer 1

2

You should probably use a matrix instead:

Z = zeros(100,numSignals);
for n=1:numSignals
    Z(:,n) = loadSignal(n);
end

Then you can call back the column vector you want with

Z(colIndex,:)

Matlab will not allow you to put anything other than a number into an entry of an array. If you really want the data structure you describe, then you will need to use a cell array instead. You can do this by

Z = cell(1,numSignals);
for n=1:numSignals
    Z{n} = loadSignal(n);
end
Sign up to request clarification or add additional context in comments.

2 Comments

Im getting the following error when using the cells ??? Conversion to cell from double is not possible. Error in ==> problem1 at 20 Z(n) = loadSignal(n);
nvm i needed to use {} to reference the index instead of (), thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.