save maximum column to excel

1 次查看(过去 30 天)
Debbie Oomen
Debbie Oomen 2017-10-12
回答: Guillaume 2017-10-12
I have 4 columns in my file. Column 1 consists of the time and columns 2 - 4 are EMG files. I want matlab to find the column with the maximum EMG value and save only that column with the time column as a new excel/csv file. So far I have this script:
close all; clear all; clc
MVCfilename = uigetfile('*.xlsx', 'Select "allMVCs" file');; %gets file
file = xlsread(MVCfilename);
maxVal = max(file(:,2:4));
[mmaxVal col_no] = max(maxVal);
file(col_no);
csvwrite('naam.csv',file)
The code works great however the file variable returns as the original file with 4 columns

回答(1 个)

Guillaume
Guillaume 2017-10-12
file(col_no);
does nothing. It asks for the col_no'th element of file and doesn't put it anywhere. Then, with
csvwrite('naam.csv',file)
you save the unmodified original variable, so of course, you still have the 4 columns. To fix:
csvwrite('naam.csv',file(:, col_no));
Note: since you don't need the maximum value in the 2nd max call, this would be better:
[~, col_no] = max(maxVal); % ~ tells matlab to ignore that output

类别

Help CenterFile Exchange 中查找有关 Data Import from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by