replace cell content of excel from matlab script

57 ビュー (過去 30 日間)
Deepan Muthusamy
Deepan Muthusamy 2021 年 7 月 7 日
コメント済み: Mathieu NOE 2021 年 7 月 7 日
i have an excel sheet of data having (400x256). The columnsn of each row B,D, F, F+2, F+4,..... till 256 having value either 80 or 90. i want to replace those values with "pass" or "fail".
I am using matlab 2018a. so i am using xlsread/xlswrite funtions.
I tried the below code but it is not working...
I read the excel to a variable in matlab
data = xlsread("filename.xlsx","sheet").
then tried changing that particular cell,
if data(1,2) == 80
data(1,2) = "pass"
end
then write back the data to excel.
xlswrite("filename.xlsx", data, "sheet")
but i don't see "pass" in B1 cell instead seeing an empty cell.

採用された回答

Mathieu NOE
Mathieu NOE 2021 年 7 月 7 日
hello
this is my suggestion - convert your data (numeric double) to cell array first
and more robust if statement as numerical round off can cause some issues it you do "strict" comparison with the given value (here 80), so use a tolerance to account for this
data = xlsread('filename.xlsx','sheet');
cellarray = num2cell(data);
tol = 1e-12;
% then tried changing that particular cell,
if abs(cellarray{1,2} - 80) < tol
cellarray{1,2} = "pass"
end
% then write back the data to excel.
xlswrite('filename.xlsx', cellarray, 'sheet')
  2 件のコメント
Deepan Muthusamy
Deepan Muthusamy 2021 年 7 月 7 日
this works for me. thank you @Mathieu NOE
Mathieu NOE
Mathieu NOE 2021 年 7 月 7 日
My pleasure

サインインしてコメントする。

その他の回答 (1 件)

Günter Gsellmann
Günter Gsellmann 2021 年 7 月 7 日
In your case you are creating a NaN, as your "data" is only numeric.

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by