Sorting Excel values into new vector

1 vue (au cours des 30 derniers jours)
John Corrado
John Corrado le 27 Août 2021
Réponse apportée : darova le 29 Août 2021
Hi, I'm sort of lost when it comes to sorting data. I have a .xlxs file that contains data in a single column that's formated as four values. The first value is 255 , never changes, and I planned on using that as a marker to start sorting. I've imported the table and made it a vector, however, I have no clue on how to add every other value into a certain vector.
The data looks something like:
255 % Start sorting
4.66 % Data set 1
54.52 % Data set 2
2.59 % Data set 3
255 % Start sorting
4.65 % Data set 1
53.98 %And so on and so forth
And my code looks something like this:
clear all
filename = "CARACT 255 60.XLSX"; % Set filename
DATA = xlsread(filename,'A:A') % Read data table
DUTY = 1; % Counter 1
TVIN = 2; % Counter 2
TEMP = 3; % Counter 3
LVIN = 4; % Counter 4
for i = 1:length(DATA)
DUTY_OUT = xlsread % Sort 1
TVIN_OUT = xlsread % Sort 2
TEMP_OUT = xlsread % Sort 3
LVIN_OUT = xlsread % Sort 4
DUTY = DUTY+1; % Add to counter 1
TVIN = TVIN+1; % Add to counter 2
TEMP = TEMP+1; % Add to counter 3
LVIN = LVIN+1; % Add to counter 4
end
Any help would be much appreciated!

Réponses (1)

darova
darova le 29 Août 2021
Try this
ind = find(abs(data-255)<0.1); % find all '255' numbers
ind(end+1) = numel(data)+1; % add last index+1
for i = 1:numel(ind)-1
ii = ind(i)+1:ind(i+1)-1; % select data between current '255'
data(ii) = sort(data(ii)); % sort data
end

Catégories

En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by