How to insert a single element vector in a table ?

5 vues (au cours des 30 derniers jours)
RAJEEV
RAJEEV le 15 Jan 2024
Commenté : Hassaan le 15 Jan 2024
I have a table containing four columns. The second and third column contains the measured CIR value and corresponding fitted trend. The fourth column is the error value for each time stamps. I want to create a fifth column which reflects the RMSE value for the second and third column.
Problem: If I am using the following code line :
testresults.RMSE(1,1) = rmse(Measured,Trend);
It is giving me a RMSE value at in 1st row of RMSE column followed by all zeros.
I dont want these zeros rather only a single element in the RMSE column.

Réponse acceptée

Hassaan
Hassaan le 15 Jan 2024
Modifié(e) : Hassaan le 15 Jan 2024
% Load your data from Excel file, assuming it is saved as 'TestF2.xlsx'
filename = 'TestF2.xlsx'; % replace with your actual file path if different
opts = detectImportOptions(filename);
testresults = readtable(filename, opts);
% Calculate RMSE
Measured = testresults.Measured; % Replace with actual column names if different
Trend = testresults.Mea_Trend; % Replace with actual column names if different
RMSE_value = sqrt(mean((Measured - Trend).^2));
% Create the 'RMSE' column with NaN values
testresults.RMSE = NaN(height(testresults), 1);
% Assign the RMSE value to the first row of the 'RMSE' column
testresults.RMSE(1) = RMSE_value;
% Write the updated table back to the same Excel file, in the same sheet, starting at column E
writetable(testresults, filename, 'Sheet', 1, 'Range', 'A1'); % This will overwrite the existing sheet with the new data
This code snippet assumes that the Excel file 'TestF2.xlsx' is in the MATLAB current directory. It will read the file, calculate the RMSE, add the new column, and then save the table back to the same Excel file, starting at cell E1 which corresponds to the new fifth column. If your 'Measured' and 'Mea_Trend' columns have different names, make sure to replace them in the code with the actual names used in your Excel file.
---------------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.
  2 commentaires
RAJEEV
RAJEEV le 15 Jan 2024
Thank You for your prompt response.
Hassaan
Hassaan le 15 Jan 2024
You are welcome.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by