How to store multiple column vector generated from a for loop?
Mostrar comentarios más antiguos
I have a function called func which returns A, B, C and D. This A, B, C, D each are 12 elements column vector. I am using this code
for delta = 0: 1: 40
[A,B,C,D] = func(delta);
end
Now after completing the for loop i will get 41 sets of A, B, C and D. How can i store them together?
I tried this
store = 0
for delta = 0: 1: 40
[A(store),B(store),C(store),D(store)] = func(delta);
end
But obviously there is an error like A(I) = X: X must have the same size as I. cause A is storing a 12 element column vector.
Respuesta aceptada
Más respuestas (1)
clc; clear all ;
iwant = zeros(4,12,40) ;
for delta = 1: 40
[A,B,C,D] = func(delta);
iwant(:,:,delta) = [A B C D] ;
end
Note that MATLAB index starts from 1 not zero.
6 comentarios
Mr. 206
el 12 de Nov. de 2018
KSSV
el 12 de Nov. de 2018
delta = 0: 0.077: 0.385 ;
N = length(delta) ;
iwant = zeros(4,12,N) ;
for i = 1:N
[A,B,C,D] = func(delta(i));
iwant(:,:,i) = [A B C D] ;
end
Mr. 206
el 12 de Nov. de 2018
KSSV
el 12 de Nov. de 2018
delta = 0: 0.077: 0.385 ;
N = length(delta) ;
A = zeros(12,N) ;
B = A ;
C = A ;
D = A ;
for i = 1:N
[a,b,c,d] = func(delta(i));
A(:,i) = a ; B(:,i) = b ;
C(:,i) = c ; D(:,i) = d ;
end
KSSV
el 12 de Nov. de 2018
YOu should check your function output...
Mr. 206
el 12 de Nov. de 2018
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!