Save values from iterations

조회 수: 1 (최근 30일)
stelios loizidis
stelios loizidis 2021년 1월 4일
답변: Manas Shukla 2022년 2월 3일
for r=1:5
for w=1:100
Datax(r,:)=(W'*NewDatax(r,:)')'; % size: NewDatax 5X70
ntempDatax=Datax+b;
Values(r,:)=ntempDatax(r,:)*z; % size: Values 5X30
% Mean Absolute Error
MAE(w,r)=mae(Values(r,:)-ActualData); % size: MAE: 5X100
end
end
% Find the smallest value and position of each column
for r=1:5
[min_MAE(r),Index(r)]=min(MAE(:,r))
end
% Comparison of the 5 values ​​obtained from above and selection of the smallest value and the position.
[min_Final_error,Final_Index]=min(min_MAE)
Final_Results=ForecastValues(Final_Index,:);
% Confirmation of results
a=mae(Final_Results-ActualData);
In the above code I have the matrix NewDatax (5X70) and I select each row of the specific matrix (NewDatax) and the above procedure is done and then I calculate the MAE. After each column of the matrix MAE I find the smallest value but also the position of the smallest value. Next, I compare the smallest value of each column and select the smallest value and its position so that all 30 values ​​are selected which give this small result. In the end I re-calculate the error-mae (a) to confirm if the results are correct. However, the following issue arises: The result given by a is the mae given by the values ​​of the last iteration. That is, the values ​​from the last iteration (5x30) are stored in matrix Values. How to save all values ​​from each iteration? That is, the size of the matrix Values should be 500x30. Your help is important.

답변 (1개)

Manas Shukla
Manas Shukla 2022년 2월 3일
As per my understanding, you want the variable “Value” to be of size (500*30) instead of (5*30). Since dimensions of the variable “Value” depends on the variable “Datax”, you should change the way you are indexing in “Datax”. Replace line number 3 of the code snippet you provided in the question with following:
Datax(100*(r-1)+w,:)=(W'*NewDatax(r,:)')';
This will modify the dimensions of the variable “Value” to (500*30).

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by