フィルターのクリア

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 Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by