- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
How to insert a single element vector in a table ?
5 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Hassaan
2024 年 1 月 15 日
編集済み: Hassaan
2024 年 1 月 15 日
% 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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!