필터 지우기
필터 지우기

Read Excel and write output

조회 수: 6 (최근 30일)
MINATI PATRA
MINATI PATRA 2024년 1월 13일
댓글: MINATI PATRA 2024년 1월 15일
R = xlsread('Book1.xlsx') %% Excel sheet (Book1.xlsx) is in 'D' drive
R = 20×3
0.0100 0.0100 0.0100 0.0300 0.0100 0.0100 0.0100 0.0300 0.0100 0.0300 0.0300 0.0100 0.0100 0.0100 0.0300 0.0300 0.0100 0.0300 0.0100 0.0300 0.0300 0.0300 0.0300 0.0300 0.0100 0.0200 0.0200 0.0300 0.0200 0.0200
A = 1; B = 2; C = 3;
Nu = A*p1 + B*p2 + C*p3;
Unrecognized function or variable 'p1'.
I want Matlab to read Excel sheet, columns C, D, and E, then calculate Nu (column F) by the above formula and write the respective values in column F in that excel sheet automatically.

채택된 답변

Voss
Voss 2024년 1월 13일
filename = 'Book1.xlsx'; % path to your file, e.g., 'D:\PK79\Book1.xlsx'
% read the file to a table:
T = readtable(filename)
T = 20×4 table
p1 p2 p3 NU ____ ____ ____ ___ 0.01 0.01 0.01 NaN 0.03 0.01 0.01 NaN 0.01 0.03 0.01 NaN 0.03 0.03 0.01 NaN 0.01 0.01 0.03 NaN 0.03 0.01 0.03 NaN 0.01 0.03 0.03 NaN 0.03 0.03 0.03 NaN 0.01 0.02 0.02 NaN 0.03 0.02 0.02 NaN 0.02 0.01 0.02 NaN 0.02 0.03 0.02 NaN 0.02 0.02 0.01 NaN 0.02 0.02 0.03 NaN 0.02 0.02 0.02 NaN 0.02 0.02 0.02 NaN
% update the NU column:
A = 1; B = 2; C = 3;
T.NU = A*T.p1 + B*T.p2 + C*T.p3
T = 20×4 table
p1 p2 p3 NU ____ ____ ____ ____ 0.01 0.01 0.01 0.06 0.03 0.01 0.01 0.08 0.01 0.03 0.01 0.1 0.03 0.03 0.01 0.12 0.01 0.01 0.03 0.12 0.03 0.01 0.03 0.14 0.01 0.03 0.03 0.16 0.03 0.03 0.03 0.18 0.01 0.02 0.02 0.11 0.03 0.02 0.02 0.13 0.02 0.01 0.02 0.1 0.02 0.03 0.02 0.14 0.02 0.02 0.01 0.09 0.02 0.02 0.03 0.15 0.02 0.02 0.02 0.12 0.02 0.02 0.02 0.12
% write the table back out to file:
writetable(T,filename,'WriteMode','overwritesheet')
% check the result:
T = readtable(filename)
T = 20×4 table
p1 p2 p3 NU ____ ____ ____ ____ 0.01 0.01 0.01 0.06 0.03 0.01 0.01 0.08 0.01 0.03 0.01 0.1 0.03 0.03 0.01 0.12 0.01 0.01 0.03 0.12 0.03 0.01 0.03 0.14 0.01 0.03 0.03 0.16 0.03 0.03 0.03 0.18 0.01 0.02 0.02 0.11 0.03 0.02 0.02 0.13 0.02 0.01 0.02 0.1 0.02 0.03 0.02 0.14 0.02 0.02 0.01 0.09 0.02 0.02 0.03 0.15 0.02 0.02 0.02 0.12 0.02 0.02 0.02 0.12
  댓글 수: 1
MINATI PATRA
MINATI PATRA 2024년 1월 14일
Dear Voss
A Salute to your ideas, it worked for me. It is actually a sample of my original work. I applied your technique with bvp5C code but unable. Please have a look into the link of same type work.
https://in.mathworks.com/matlabcentral/answers/2069731-read-excel-and-write-the-output-in-same-sheet-in-three-columns

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

추가 답변 (1개)

Image Analyst
Image Analyst 2024년 1월 13일
What is p1, p2, and p3? You might try
R = xlsread('Book1.xlsx') %% Excel sheet (Book1.xlsx) is in 'D' drive
A = R(:, 1);
B = R(:, 2);
C = R(:, 3);
Nu = A*p1 + B*p2 + C*p3;
  댓글 수: 3
Image Analyst
Image Analyst 2024년 1월 14일
You accepted Voss's answer so I guess you got it all figured out now.
MINATI PATRA
MINATI PATRA 2024년 1월 15일
yes

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

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by