Azzera filtri
Azzera filtri

Read 2 specific columns in excel file

8 visualizzazioni (ultimi 30 giorni)
Vlatko Milic
Vlatko Milic il 9 Gen 2018
Commentato: dpb il 9 Gen 2018
Hi, I am quite new to Matlab and have a question about reading specific columnws from excel files. I am interested in column A and G. There is data in the other columns but I am not interested in it. The code follows:
ImportedData{fol_no,file_no} = readtable(char(fullfile(fileInfo(1).folder,fileNames(file_no))));
el=table2array(ImportedData{fol_no,file_no}(:,1,:,7));
I get a message consisting of: You cannot subscript a table using linear indexing (one subscript) or multidimensional indexing (three or more subscripts). Use a row subscript and a variable subscript.
I can import one of the columns, either A or G, but not both simultaneously. I guess the problem is connected to "table2array" as the array only deals with one column?
So my question to you is- how can I import the columns simultenously? Pleaste note that I am performing this procedure for a no.of files

Risposta accettata

dpb
dpb il 9 Gen 2018
In the addressing expression (:,1,:,7) there are four dimensions, not just two -- the first colon will reference all rows, then 1,:,7 looks like another 3D subscript. Try
el=table2array(ImportedData{fol_no,file_no}(:,[1 7]);
I'd suggest recasting the loop however to process each file in sequence after reading it instead of storing the input data into an array of tables. You don't outline the requirements but if each file is independent of the others then there's no need to keep all; if you do need to build a full set from the files then you should again just read each file and append the next set onto the previous, still not needing an array for the initial input.
More details of what are doing next would lead to more specific answers in that regards.
  3 Commenti
dpb
dpb il 9 Gen 2018
Modificato: dpb il 9 Gen 2018
That's a trivial usage of logical addressing; the bigger question still revolves about whether these sums are to be computed on a file at at time or over all files (albeit if they're just sums then a running total is mathematically the same as the sum of sums).
Either way, it seems there's no need to do anything but process the data as you read each file -- unless there's more to be done yet than outlined.
dpb
dpb il 9 Gen 2018
VM Answer moved to Comment -- dpb
The files are independent by each other, in fact they all have the same structure. They are located in subfolders where the no.of excel files in each folder varies from the other. Each subfolder represents an adress, and for each Adress I want to sum annual data from the excel files. Therefore, the next step is to sum annual data within each subfolder for all Excel files within the subfolder. That was a clarification of the problem :) moreover, why I need to differentiate between the various cells in the column with 1s or 2s is because the 1s represent monthly data, and the 2s daily data. And it is the monthly data I am interested in

Accedi per commentare.

Più risposte (0)

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