store values from a loop in a vector

Hi,
I have a for loop that calculates "n" values for each file. Meaning n values are calculated for file 1 and then a different n values are calculated for file 2 etc.. I just want to form arrays that contains the ith value from each of the n value. Meaning [1a, 1b,...] then [2a, 2b,...]...[na, nb,...] How would I do that?

Risposte (1)

Azzi Abdelmalek
Azzi Abdelmalek il 5 Gen 2014

0 voti

Just creat a matrix nxm

6 Commenti

anna
anna il 5 Gen 2014
Modificato: Azzi Abdelmalek il 5 Gen 2014
Yes, but how would I assign it to n vectors instead of having a matrix. A shortened version looks something like this:
for k = 1:length(xlFiles)
col1=data(:,14);
col2=data(:,17);
j=length(col2);
for i=1:j-1
y=col1(i+1)-col1(i);
x=col2(i+1)-col2(i);
ratio = atand(y/x);
vecC(k,:)=cosd(ratio)
end
end
This is what I put for vecC but I really want vecC to be 1xk vectors of the ith "ratio" from each file.
Maybe you want to change vecC(k,:)=cosd(ratio) to
vecC(k,i)=cosd(ratio)
yeah I did that before...putting vecC(k,i)=cosd(ratio) but then it seems to repeat it n times for each file...giving n vecC arrays for each file
But you have to read the data from each file, this does not appear in your code
yes, sorry, i shortened it but there is a part where I read each file with the loop with k indices. xLfiles=dir(myFilePattern)
for k = 1:length(xlFiles)
%read data from files
y=diff(data(:,14)');
x=diff(data(:,17)');
ratio = atand(y./x);
vecC(k,:)=cosd(ratio)
end

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Richiesto:

il 5 Gen 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by