필터 지우기
필터 지우기

How to insert a single element vector in a table ?

조회 수: 3 (최근 30일)
RAJEEV
RAJEEV 2024년 1월 15일
댓글: Hassaan 2024년 1월 15일
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.

채택된 답변

Hassaan
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
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.
  댓글 수: 2
RAJEEV
RAJEEV 2024년 1월 15일
Thank You for your prompt response.
Hassaan
Hassaan 2024년 1월 15일
You are welcome.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by