Hello everybody, I want to save the following code result in matrix without overwrite the old result and finally export it as xls file?

2 ビュー (過去 30 日間)
for n=1:5
for z=1:4
sheetNumber = z;
range = 'A1:A50';
if(z==1)
Weight = rot90(W1);
elseif(z==2)
Weight = rot90(W2);
elseif(z==3)
Weight = rot90(W3);
else
Weight = rot90(W4);
end
aval=length(a(:,1));
for i=1:aval
for j= 1:length(Weight)
if Wcriteria(1,j)== 0
Y(i,j)=min(a(:,j))/a(i,j);
else
Y(i,j)=a(i,j)/max(a(:,j));
end
end
end
for i=1:aval
PWSM(i,1)=sum(Y(i,:).*Weight);
end
Preference_Score_of_Weighted_Sum_Model = num2str([PWSM])
[~,idx]=ismember(PWSM,sort(PWSM,'descend'))
for i=1:5
RN(N,i)=idx(i);
end
xlswrite( filename,sheetNumber,RN,range)%'OutputData idx' )
end
This code run 5 times and each time will run 4 times I want to save all results (idx) without overwite the old results, i have tried with this sub code but in saving the result i have a problem.
Thank you in Advance

回答 (1 件)

Nithin
Nithin 2025 年 2 月 14 日
The ‘range’ variable should be dynamically adjusted to ensure that each iteration writes to a different range in the Excel sheet. This prevents overwriting previous results.
range = sprintf('A%d:A%d', (n-1)*50 + 1, n*50); % Adjust the range for each iteration
You can either write to different sheets or adjust the range (as shown above) within the same sheet to ensure results from different iterations are not overwritten. If you prefer separate sheets for each n iteration, you can modify the ‘sheetNumber’ to include the iteration number
sheetNumber = sprintf('Sheet%d', (n-1)*4 + z)[SJ2]
Hope this is helpful

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by