Export data from plot into a table *.txt
8 views (last 30 days)
Show older comments
I think this a very basic question, but i am new on this and i have been looking for a while and still i cannot find the answer.
I am using App Designer and I have a a function and then i polot it. Then i just want to save the data generated in a table in a text file. Let's say:
x = -5:0.1:45;
y = 4*sqrt(1 + (((x*1000) - z2)/2).^2);
plot(app.UIAxes,x,y,'r')
Now i just want to save this data on a table that you can open in a text file. I have tried this:
T = table(x,y)
writetable(T,'tabledata.txt');
type tabledata.txt
However the result is a lot of numbers with no order.. What i need is soemthing like this:
x y
1 1.2
2 2.3
3 3.4
4 4.5
Thanks in advance!
0 Comments
Answers (1)
Riya
on 3 Mar 2025
Hi,
I understand that you want to save the generated data in a structured text file. The issue is that “table” function requires column vectors as inputs. So, you should transpose x and y using x’ and y’. Also, you should change the delimiter of the “writetable” function from default delimiter “comma” to tab(“\t”) or space(“ “). To display the variable names “x” and “y”, set the “WriteVariableNames” property to “true”.
T = table(x', y', 'VariableNames', {'x', 'y'}); % Ensure column vectors
% Write table to a text file with tab delimiter
writetable(T, 'tabledata.txt', 'Delimiter', '\t', 'WriteVariableNames', true);
This will generate a text file in the desired structure.
For more information about “writetable” function, refer to the following documentation:
Thanks!
0 Comments
See Also
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!