Putting outcome of multiple values from for loop in one table

2 ビュー (過去 30 日間)
Sven Dobbe
Sven Dobbe 2022 年 4 月 1 日
編集済み: Ayush Modi 2023 年 10 月 23 日
Hi everyone,
I have 6 different variables (33x1) in a for loop. I would like to store all the data in one table. My for loop looks as followed:
j = [x y z a b c];
for i = 1:6
k = j(:,i);
kInt3 = [k(1) k(17) k(33)];
kInt5 = [k(1) k(9) k(17) k(25) k(33)];
kInt8 = [k(1) k(5) k(9) k(13) k(17) k(21) k(25) k(29) k(33)];
Interpolatiek3 = interp1(Frames3,kInt3,SortedCap, Interpolatie);
Interpolatiek5 = interp1(Frames5,kInt5,SortedCap, Interpolatie);
Interpolatiek8 = interp1(Frames8,kInt8,SortedCap, Interpolatie);
end
Does anyone know how i can get the values back from Interpolatiek3-5-8 in a single table for x,y,z,a,b and c? Interpolatiek3, Interpolatiek5 and interpolatiek8 obviously have to be different tables, but all the tables need to contain the x,y,z,a,b and c values.
Thanks in advance!
  1 件のコメント
Ishaan Mehta
Ishaan Mehta 2022 年 6 月 27 日
Hey Sven
Can you provide an example table with a few rows? That would help in understanding the requirement better. I don't understand "but all the tables need to contain the x,y,z,a,b and c values". As I understand, these 6 variables have are vectors with 33 elements each. So, I am not sure about putting them into the table
Ishaan

サインインしてコメントする。

回答 (1 件)

Ayush Modi
Ayush Modi 2023 年 9 月 28 日
編集済み: Ayush Modi 2023 年 10 月 23 日
Hey Sven,
I understand you would like to know how to store the data generated by “interp1” function into a table where output for each variable (“x”, ”y”, ”z”, ”a”, ”b” and “c”) is represented in a separate column. You can achieve this by following steps mentioned below:
  1. Declare different tables you want to create before the for loop by using “table” method.
t3 = table();
2. Inside the for loop, you can add the values of “interp1” function as a new column for each iteration in each table. Since “interp1” returns (1x3) matrix, you would need to transpose the output before adding to the table.
t3.newc = Interpolatiek3';
3. Rename the new column by using “table.Properties.VariableNames” property of the table. (Note – This is necessary because if we do not rename the column name, in the next iteration the value in the table will get replaced.)
t3.Properties.VariableNames{end} = columnNames(i);
You can refer to the below MathWorks documentation for more information on “table” function:
Hope this helps!

カテゴリ

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

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by