Filter löschen
Filter löschen

save maximum column to excel

1 Ansicht (letzte 30 Tage)
Debbie Oomen
Debbie Oomen am 12 Okt. 2017
Beantwortet: Guillaume am 12 Okt. 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

Antworten (1)

Guillaume
Guillaume am 12 Okt. 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

Kategorien

Mehr zu Data Import from MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by