How to export the result of for loop to the excel file

조회 수: 1 (최근 30일)
kaivlya patel
kaivlya patel 2020년 5월 21일
댓글: KSSV 2020년 5월 21일
Hi all
I have the following code,
for n = 2: frontier_idx
plot (pareto_frontier (n: frontier_idx, 2), pareto_frontier (n: frontier_idx, 3), 'rs' , 'LineWidth' , 3, 'Tag' , sprintf ( 'ix% d \ n% s' , 1, join ( pareto_frontier_archs (n, :))))
end
for k = 1: length (pareto_frontier (:, 2))
fprintf ( 'x =% f, y =% f. \ n' , pareto_frontier (k, 2), pareto_frontier (k, 3));
end
and the answer of this code, I get is:
x = 4,200,000, y = 6,819,000.
x = 4.040000, y = 6.808000.
x = 4.000000, y = 6.797000.
x = 3.870000, y = 6.568000.
x = 3.570000, y = 6.380000.
x = 3.530000, y = 6.369000.
x = 3.370000, y = 6.358000.
x = 3.330000, y = 6.347000.
x = 3,200,000, y = 6,118,000.
x = 3.070000, y = 5.901000.
x = 3.030000, y = 5.890000.
x = 2,900,000, y = 5,661,000.
Now, I want to export this x and y coordinate values, which I have got from the above code, to the excel / macro excel file. I have already generated the excel file with the writematrix command to export some prior data. And for the prior data it is working properly but comming to the above for loop and its result, it is not working.
I have tried xlswrite function and also the writematrix / writecell function tso do so, but it is not working. The reason to use writematrix is ​​that firstly the file I kept was excel macro file. But when it was not working, I tried to do the same with the normal .xls file. But the result is not being exported to any of the excel file.
Any help in this perticular would be really appreciated and I would be really greatful.

채택된 답변

KSSV
KSSV 2020년 5월 21일
A = pareto_frontier(:,2:3) ;
xlswrite('test.xlsx',A)
Also have a look on write2table.
  댓글 수: 2
kaivlya patel
kaivlya patel 2020년 5월 21일
Its working. Thank you. Now I will try this same with .xlsm file.
Thank you very much again.
KSSV
KSSV 2020년 5월 21일
Thnaks is accepting the answer... :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by