Clear Filters
Clear Filters

save maximum column to excel

1 view (last 30 days)
Debbie Oomen
Debbie Oomen on 12 Oct 2017
Answered: Guillaume on 12 Oct 2017
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

Answers (1)

Guillaume
Guillaume on 12 Oct 2017
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

Categories

Find more on Data Import from MATLAB 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!