- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
How to insert a single element vector in a table ?
5 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Hassaan
on 15 Jan 2024
Edited: Hassaan
on 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
Feel free to contact me.
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!