File-loop, for loop,importing excel data
古いコメントを表示
Hi everyone,
I have the following code, I have problem with the read-in-for-loops.
-I would like to read in several .csv files then export them separetly to excels -even different sheets is okay (it would be great to have the same title/name)
-then I would like to import/read-in these new excel files and work with the 16th column to find local maximas.
I know it's fulll with mistakes, and I am sorry about that, I am really new to MatLab coding I am studying it by myself, so please instead of judging the code, could you help me out?
I would really appraciate any help, thanks in advance, Grace.
4 件のコメント
GH
2020 年 6 月 21 日
Thiago Henrique Gomes Lobato
2020 年 6 月 21 日
You don't need to save the csv to excel just to convert it to numeric. Considering your data is a string only because, in the file, they have a title or something like this, you could convert it to numeric as:
csv2table = readtable(filename(i));
NumericVal = arrayfun(@(x)num2str(x),csv2table{2:end,:},'UniformOutput',false)
Dear Grace, I do not understand why you want to export it to excel and import it again to have numerical values. Is the first import into MATLAB only to change the file format?
I am sure you can quickly convert it in MATLAB, too. For example if you have strings, you can use "str2double" or "str2num". In order to help you there specifically and get the import right, I would have to see one of your csv files as an example.
I could not run your code as I do not have your .csv but think that the second half can be shortened a lot by still doing what you want:
for ii = 1: excel_files
data = xlsread('csv2excel.xls'); % should be returned as a matrix already
[rows, columns] = size(data); % The size of the matrix (the number of
% elements is the same for all columns
% in a matrix, also nr 16)
is_max_rows = islocalmax(data(:,16)) % logical vector of all local max in
% column 16
local_max_col_16 = data(is_max_rows, 16) % value of local maxima in column 16
[rowsWith50, colsWith50] = find(data == 50); % Find out all the rows/cols that have a 50
% in them.
theMax = max(data(:,unique(colsWith50))) % get the max of the columns with a 50
% without repetition of the columns with
% 2x or more 50
end
Best,
Mara
GH
2020 年 6 月 21 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!