write a formula for excel

5 次查看(过去 30 天)
hi I want to write a long formula in excel like this: if(A1=$C1,1,if(A1=0,0,-.33))+if(A2=$C2,1,if(A2=0,0,-.33))+ ... for 1 to 100 to avoid copy and paste 100times I write a code in matlab but it error I wrote:
for i=1:100 display('if(Ai=$Ci,1,if(Ai=0,0,-.33))+') end how to change my code to write formula correctly?

采纳的回答

Geoff Hayes
Geoff Hayes 2014-9-4
Hossein - just use fprintf
for k=1:100
fprintf('if(A%d=$C%d,1,if(A%d=0,0,-.33))+',k,k,k);
end
The above will write a single line to the Command Window with all the if statements. If you want each statement on a separate line, just add \n to the end of the string
fprintf('if(A%d=$C%d,1,if(A%d=0,0,-.33))+\n',k,k,k);

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by