Putting outcome of multiple values from for loop in one table
2 次查看(过去 30 天)
显示 更早的评论
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
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
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:
- 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!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!