write a formula for excel

6 views (last 30 days)
hossein
hossein on 4 Sep 2014
Answered: Geoff Hayes on 4 Sep 2014
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?

Accepted Answer

Geoff Hayes
Geoff Hayes on 4 Sep 2014
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);

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!