필터 지우기
필터 지우기

Tabulating the data obtained for my Matlab code

조회 수: 1 (최근 30일)
helin özdemir
helin özdemir 2024년 5월 20일
댓글: Star Strider 2024년 5월 21일
With the code I stated below, I obtain 2 column graphic data as x and y. The data I obtained appear separately on the right. One writes as a column, the other as a row. I would like help in updating my code to create a txt or Excel file with these two data as columns from top to bottom.
The data I obtained look like this, separately, one as a column and the other as a graph. I want it to give me this data as columns in txt or excel.
I upload the data I use for the code to work as a txt file.
data = readmatrix('Naca LD0006 6R.txt');
f = fit(data(:,1), data(:,2),'smoothingspline','SmoothingParam',0.3);
xi = -15:1:18; % or -15:0.5:18 or whatever
yi = f(xi);
figure
plot(f,data(:,1),data(:,2))
hold on
plot(xi,yi,'o','MarkerFaceColor','g','DisplayName','1° intervals')
set(get(gca(),'Legend'),'Location','best');

답변 (1개)

Star Strider
Star Strider 2024년 5월 20일
편집: Star Strider 2024년 5월 20일
Create a table array with your variables (that I assume are ‘xi’ and ‘yi’ here) and then use writetable to save them as an Excel file. Use the colon, : operator to force both of them to be column vectors.
Try this —
data = readmatrix('Naca LD0006 6R.txt');
f = fit(data(:,1), data(:,2),'smoothingspline','SmoothingParam',0.3);
xi = -15:1:18; % or -15:0.5:18 or whatever
yi = f(xi);
figure
plot(f,data(:,1),data(:,2))
hold on
plot(xi,yi,'o','MarkerFaceColor','g','DisplayName','1° intervals')
set(get(gca(),'Legend'),'Location','best');
Result = table(xi(:), yi(:), 'VariableNames',{'xi','yi'})
Result = 34x2 table
xi yi ___ _________ -15 -0.67499 -14 -0.71457 -13 -0.74548 -12 -0.77316 -11 -0.80363 -10 -0.83323 -9 -0.84495 -8 -0.80726 -7 -0.71686 -6 -0.61567 -5 -0.51768 -4 -0.41271 -3 -0.29851 -2 -0.18381 -1 -0.069523 0 0.04048
writetable(Result,'xi_yi.xlsx')
Read_xi_yi = readtable('xi_yi.xlsx')
Read_xy_yi = 34x2 table
xi yi ___ _________ -15 -0.67499 -14 -0.71457 -13 -0.74548 -12 -0.77316 -11 -0.80363 -10 -0.83323 -9 -0.84495 -8 -0.80726 -7 -0.71686 -6 -0.61567 -5 -0.51768 -4 -0.41271 -3 -0.29851 -2 -0.18381 -1 -0.069523 0 0.04048
EDIT — Corrected typographical error.
EDIT — (20 May 2024 at 20:40)
Added colon operator citation and link.
.
  댓글 수: 2
helin özdemir
helin özdemir 2024년 5월 21일
Thank you so much, So, can I add something to the code that can transfer this data to Excel?
Star Strider
Star Strider 2024년 5월 21일
My pleasure!
The writetable call creates an Excel file (that I call ‘xi_yi.xlsx’, you can call it whatever you want) that you should be able to open in Excel or any application that uses Excel and allows those files.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by