Need to print the output to newline while creating a table
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Praveen Kumar Kannappan Jayaraman
am 26 Nov. 2022
Kommentiert: Star Strider
am 27 Nov. 2022
I am trying to create a table while running a loop. However, the output is printing the variable name each time it iterates over the loop. I know we have \n command while using fprintf but for table it doesn't seem to work. Please help! Thanks in advance. ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1208798/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1208798/image.png)
0 Kommentare
Akzeptierte Antwort
Star Strider
am 26 Nov. 2022
In the loop, subscript the different assignments, for example:
Var1(j,:) = type(j);
Var2(j,:) = dx(j);
and so for the rest. (The subscript ‘(j,:)’ forces a column vector, important when creating a table.)
Then, after the loop, create the table.
Example —
Varname = {'type','dx','dy'};
for j = 1:5
Var1(j,:) = randi(j);
Var2(j,:) = randi(10^j);
Var3(j,:) = randi(100^j);
end
T1 = table(Var1,Var2,Var3, 'VariableNames',Varname)
.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Database Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!