Hello,
I have 2 columns in Excel that I would need to calculate in Matlab. In the first column I have a formula: =IF(J2=1;IF(ISNUMBER(K1);K1+1;1);0) In the second column: =IF(AND(J2=1;J3<>1);K2;0) After column J, I have it calculated in matlab. Thank you very much for the advice.
I created column J in matlab with the command: T.Platoon=double(T.CasRozdiel<=4). I have added a matlab file in the attachment.
How it looks in excel.

4 件のコメント

Rik
Rik 2022 年 8 月 23 日
I think you need this structure in Matlab (with your array A and row n):
if A(n,1)==1 && A(n,+1,1)~=1
A(n,3)=A(n,2);
else
A(n,3)=0;
end
Is this what you mean?
Zuzana Pániková
Zuzana Pániková 2022 年 8 月 23 日
編集済み: Walter Roberson 2022 年 8 月 23 日
I try:
T.Platoon1=zeros(12645,1)
if Platoon(n,1)==1 && Platoon(n,+1,1)~=1
Platoon(n,3)=Platoon(n,2 );
else
Platoon(n,3)=0 ;
end
I'm not sure what to put in for ´n´ or if I should have entered it that way at all.
Thank you for help.
Image Analyst
Image Analyst 2022 年 8 月 24 日
I'm not sure what you want. Why not simply read your existing Excel workbook in to MATLAB with readtable? The computed values (the numbers), not the formulas, are what should be read in. And since you did the computations in Excel, then numbers should be right.
Zuzana Pániková
Zuzana Pániková 2022 年 8 月 24 日
I have Excel to check whether what Matlab calculates fits with Excel. Excel can no longer calculate the new data that I have to calculate. I have a lot of data for Excel.

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

 採用された回答

Hornett
Hornett 2023 年 9 月 4 日

0 投票

I understood that you want to calculate the values of two other columns based on some conditions in MATLAB.
You can try the following code
This code will iterate over each cell value of platoon and calculate the platoonTemp based on condition if(J2=1;If(isnumber(K1);K1+1;1);0) and similarly platoonTemp2 is calculated from values of platoonTemp based on condition if(and(J2=1;J3<>1);K2;0).
n = size(T,1)
platoonTemp = zeros(n,1);
platoonTemp2 = zeros(n,1);
for i = 1:n
if T.Platoon(i)==1
if i~=1
platoonTemp(i)=platoonTemp(i-1)+1;
else
platoonTemp(i)=1;
end
end
if i~=n && T.Platoon(i)==1 && T.Platoon(i+1)~=1
platoonTemp2(i)=platoonTemp(i)
end
end
T.Temp1 = platoonTemp
T.Temp2 = platoonTemp2
I hope it answered your query

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Import from MATLAB についてさらに検索

製品

リリース

R2022a

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by