Save values from iterations

3 views (last 30 days)
stelios loizidis
stelios loizidis on 4 Jan 2021
Answered: Manas Shukla on 3 Feb 2022
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.

Answers (1)

Manas Shukla
Manas Shukla on 3 Feb 2022
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).

Categories

Find more on Elementary Math in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!