Putting outcome of multiple values from for loop in one table

2 views (last 30 days)
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 Comment
Ishaan Mehta
Ishaan Mehta on 27 Jun 2022
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

Sign in to comment.

Answers (1)

Ayush Modi
Ayush Modi on 28 Sep 2023
Edited: Ayush Modi on 23 Oct 2023
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!

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!