How to get data in different tables from specific column data using for loop?

2 vues (au cours des 30 derniers jours)
Yen Su
Yen Su le 29 Jan 2021
Commenté : darova le 1 Fév 2021
I have attached three different tables; first.xlsx, second.xlsx and third.xlsx. I imported those tables in Matlab. What I would like to do is
1) For every id from first.xlsx, get the loss value from second.xlsx for specific walkid and distance for every year. For e.g. for walkid 1 and year 1 the distance is 0.8. From second.xlsx, for walkid 1 interpolate distance 0.8 to get loss data. I would like to do for every year (1 to 5 in for loop)
2) From loss value from second.xlsx, i want to get loss1 value from third.xlsx for specific runid for every year. For .eg. for runid 1 and loss value from second.xlsx, get loss1 value by interpolation for every year.
3) I would like to get new table from above operation as shown:
Any advice and suggestion is higly appreciated.
Thank you.
  5 commentaires
darova
darova le 31 Jan 2021
Read both excel data files, make some calculations and write the data into third file
Yen Su
Yen Su le 31 Jan 2021
Yeah I get that. But the difficulty I am having is using for loop for every row for three column data of first excel file and get the value from second excel file. Could you please provide snippet of code to run this? Your idea is highly appreciated.

Connectez-vous pour commenter.

Réponses (1)

darova
darova le 31 Jan 2021
Here is an example
A1 = readtable('first.xlsx');
id = A1(:,1); % read id
walkid = A1(:,2); % read walkid
% read all necessary data ...
for i = 1:length(id)
i1 = find(id(i)==walkid); % find appropriate walkid
loss(i1) % loss
end
  2 commentaires
Yen Su
Yen Su le 31 Jan 2021
Hi,
I run the code like this
A1 = readtable('first.xlsx');
id = A1(2:end,1); % read id
walkid = A1(3:end,2); % read walkid
% read all necessary data ...
for i = 1:size(id)
i1 = find(id(i)==walkid); % find appropriate walkid
end
When I used length(id) its giving me error as "Error using tabular/length (line 189)
Undefined function 'length' for input arguments of type 'table'. Use the HEIGHT, WIDTH, or SIZE
functions instead."
when I used size(id) Its giving me error as
"Subscripting a table using linear indexing (one subscript) or multidimensional indexing (three or
more subscripts) is not supported. Use a row subscript and a variable subscript."
Also, I need to loop distance for every year . Hpw do I use for loop to get distance for each year for walkid and go to second.xlsx file. From second.xlsx file for each walk id and distance for each year I need to get loss in a new table.
I am still stucked on this. Please give me some thoughts. Your idea is highly appreciated.
Thank you.
darova
darova le 1 Fév 2021
When I used length(id) its giving me error as "Error using tabular/length (line 189)
Undefined function 'length' for input arguments of type 'table'. Use the HEIGHT, WIDTH, or SIZE
functions instead."
  • Use height then
Also, I need to loop distance for every year . Hpw do I use for loop to get distance for each year for walkid and go to second.xlsx file. From second.xlsx file for each walk id and distance for each year I need to get loss in a new table.
  • can you please re-write in formulas or something? I don't understand this

Connectez-vous pour commenter.

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by