How to add specific values from column vectors (of multiple files) to a new vector?

1 回表示 (過去 30 日間)
Jennifer
Jennifer 2013 年 5 月 8 日
Hi,
We would need help with the following problem.
We have 100 .mat- data files and each of those files contains 4 column vectors (each column vector has 50 values). With the help of people in this community we created a for-loop which reads the files, "addresses" specific columns within the files and performs simlpe calculations with the values of these columns (see commands below).
% % Select multiple Out4 files and open them
cd (thePath.data)
[F,P]=uigetfile('*.*','MultiSelect', 'on');
Re=zeros(length(F),1);
for i = 1:length(F)
data = load(F{i});
varnames = fieldnames(data);
firstvar = varnames{1};
HR1 = data.(firstvar)(:,3);
Re(i)= nanmean(HR1)
end
What we now need to do is the following:
1. We created a vector consisting of zeros of a certain length:
Z = zeros(100,1)
2. We want to extract a certain number of values from the 3rd column vecctor. The position and number of extracted values will differ from mat- data file to mat- data file.
3. The extracted values should be added to the vector Z starting at its 20th value. This is how we began with solving the problem:
Z(20:(20+MST)) = Z(20:(20+MST)) + HR1(mACToff:mACTon)
- mACToff is the first value to be extracted from the 3rd column (calculated in a previous step);
- mACTon is the last value from the 3rd column (calculated in a previous step);
- MST is mACTon - mACToff (defines the length of the extracted piece);
- HR1 is the name we assigned to the 3rd column vector (see the loop above).
4. The problem now is to add the extracted values from each .mat- data file to this one vector Z. Is it possible to do this with a nested loop or a loop or in any other way and what would the commands exactly look like?
Thank you for any suggestions!

回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by