i have written a while loop which displays 'yes' or 'no' if the difference is less than 0.5 for a given problem. how can i write this output into an excel sheet.
Ältere Kommentare anzeigen
this is the code i have used. it gives the desired result in the command window but i need it to write the output into an excel sheet. how can i incorporate that?
data=readtable("DATA.xlsx");
X=table2array(data);
i=1;
j=2;
while i<57
M=max(X(:,i));
n = mean(X(M-50:end,j),'omitnan');
m= M-50;
while m<M+1
y=X(m,j);
z=((y-n)/n)*100;
disp(z)
if (0.5>z) && (-0.5<z)
disp("YES")
else
disp("NO")
end
m = m+1;
end
i=i+2;
j=j+2;
end
3 Kommentare
KSSV
am 1 Nov. 2023
You got a matrix X, what exact operations you are doing? What you are expecting? You made the ocde complex, this can be done in few steps.
Aditi
am 1 Nov. 2023
Siddharth Bhutiya
am 1 Nov. 2023
Can you attach the DATA.xlsx? As KSSV mentioned there might be ways to simplify the code a bit.
Akzeptierte Antwort
Weitere Antworten (1)
Walter Roberson
am 1 Nov. 2023
data=readtable("DATA.xlsx");
X=table2array(data);
i=1;
j=2;
decisions = strings(0);
decision_count = 0;
while i<57
M=max(X(:,i));
n = mean(X(M-50:end,j),'omitnan');
m= M-50;
while m<M+1
y=X(m,j);
z=((y-n)/n)*100;
disp(z)
decision_count = decision_count + 1;
if (0.5>z) && (-0.5<z)
decisions(decision_count) = "YES";
disp("YES")
else
decisions(decisions_count) = "NO";
disp("NO")
end
m = m+1;
end
i=i+2;
j=j+2;
end
writematrix(decisions, FILENAME)
Kategorien
Mehr zu Spreadsheets finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!