Write the selection of a loop in excel

1 view (last 30 days)
Hello, I'm doing some tests with an excel table (4 columns and 12 rows), I need the loop to return all the rows in which a certain statement in column D is true.
I can only write in a new table the column D where I do the cycle, all other information in the table does not appear. I need them to show up.
CODE:
classe=xlsread('NumData.xlsx',1,'D:D'); %coord_h=xlsread('NumData.xlsx',1,'col_total')
xlRange1='D2'; xlRange3='A2';
n=1000; headers_1={'Easting', 'Norting', 'Altura', 'Classe'}; xlswrite('NumData_final.xlsx',[headers_1])
for i=2:classe data=classe(classe==n);
xlswrite('NumData_final.xlsx',data,sheet,xlRange1);
return
end

Accepted Answer

Bob Thompson
Bob Thompson on 1 Mar 2018
Edited: Bob Thompson on 1 Mar 2018
If I understood your question correctly, you want to keep all of the data, but sort based on data in the fourth column.
classe=xlsread('NumData.xlsx',1,); %Remove the calling to only look at column D, you want all the data
xlRange1='A2:D13'; xlRange3='A2'; % changed your range for the data array to allow for an array. I don't remember if xlswrite will allow for an array to expand from a single cell, or if it will just print what fits.
n=1000; headers_1={'Easting', 'Norting', 'Altura', 'Classe'}; xlswrite('NumData_final.xlsx',[headers_1])
for i=2:classe data=classe(classe(:,4)==n,:); % Adjusting your indexing here should call only rows where the fourth column is n, but keep data from the entire row.
xlswrite('NumData_final.xlsx',data,sheet);
return
end

More Answers (0)

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!