Export data from plot into a table *.txt
조회 수: 7 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Riya
2025년 3월 3일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!