Azzera filtri
Azzera filtri

save maximum column to excel

1 visualizzazione (ultimi 30 giorni)
Debbie Oomen
Debbie Oomen il 12 Ott 2017
Risposto: Guillaume il 12 Ott 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

Risposte (1)

Guillaume
Guillaume il 12 Ott 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

Categorie

Scopri di più su Data Import from MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by