Select data from excel sheet from specific row to specific row

4 ビュー (過去 30 日間)
Bartosz Pasek
Bartosz Pasek 2023 年 8 月 1 日
コメント済み: Voss 2023 年 8 月 1 日
Hi,
I have excel sheet with 8 columns and a lot of rows that are divided into cycles.
I need to make a chart that contains values of all rows that are between values 1...100Cykle. It should looks like below:
Is it possible to load to matlab values from specific row to another row to make chart from them?
  2 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 8 月 1 日
"Is it possible to load to matlab values from specific row to another row to make chart from them?"
Yes.
Though I don't understand what exactly the Cykle in your data is.
Can you attach your data (the excel file)? Use the paperclip button to do so.
Bartosz Pasek
Bartosz Pasek 2023 年 8 月 1 日
here is a xlsx file

サインインしてコメントする。

採用された回答

Voss
Voss 2023 年 8 月 1 日
Here is one way to read that file and break its contents up by cykle:
C = readcell('prow_KL_1.xlsx');
idx = find(cellfun(@ischar,C(:,1)));
start_rows = idx(~cellfun(@isempty,regexp(C(idx,1),'\[\d+Cykle\]','once')));
end_rows = [start_rows(2:end); size(C,1)+1];
N_cykles = numel(start_rows);
data = cell(1,N_cykles);
for ii = 1:N_cykles
C_section = C(start_rows(ii)+1:end_rows(ii)-1,:);
C_section(~cellfun(@isnumeric,C_section(:,1)),:) = [];
data{ii} = cell2mat(C_section);
end
disp(data)
Columns 1 through 11 {737×7 double} {706×7 double} {713×7 double} {709×7 double} {701×7 double} {706×7 double} {705×7 double} {698×7 double} {699×7 double} {692×7 double} {706×7 double} Columns 12 through 22 {700×7 double} {697×7 double} {703×7 double} {699×7 double} {701×7 double} {705×7 double} {692×7 double} {696×7 double} {681×7 double} {696×7 double} {694×7 double} Columns 23 through 33 {699×7 double} {699×7 double} {694×7 double} {695×7 double} {698×7 double} {692×7 double} {702×7 double} {682×7 double} {689×7 double} {698×7 double} {697×7 double} Columns 34 through 44 {692×7 double} {697×7 double} {692×7 double} {705×7 double} {698×7 double} {693×7 double} {698×7 double} {698×7 double} {698×7 double} {699×7 double} {691×7 double} Columns 45 through 55 {691×7 double} {695×7 double} {700×7 double} {687×7 double} {695×7 double} {684×7 double} {691×7 double} {688×7 double} {692×7 double} {687×7 double} {690×7 double} Columns 56 through 66 {693×7 double} {694×7 double} {692×7 double} {690×7 double} {693×7 double} {689×7 double} {693×7 double} {693×7 double} {699×7 double} {692×7 double} {691×7 double} Columns 67 through 77 {687×7 double} {692×7 double} {695×7 double} {690×7 double} {695×7 double} {691×7 double} {691×7 double} {698×7 double} {697×7 double} {693×7 double} {694×7 double} Columns 78 through 88 {693×7 double} {691×7 double} {684×7 double} {689×7 double} {693×7 double} {697×7 double} {690×7 double} {691×7 double} {681×7 double} {698×7 double} {689×7 double} Columns 89 through 99 {678×7 double} {687×7 double} {689×7 double} {694×7 double} {688×7 double} {685×7 double} {702×7 double} {690×7 double} {688×7 double} {693×7 double} {683×7 double} Column 100 {696×7 double}
data is a cell array containing a matrix of data for each cykle.
Now you can plot whatever you want, e.g.:
figure
hold on
plot(data{1}(:,1),data{1}(:,2))
plot(data{2}(:,1),data{2}(:,2))
plot(data{3}(:,1),data{3}(:,2))
legend("Cykle "+(1:3))
  1 件のコメント
Bartosz Pasek
Bartosz Pasek 2023 年 8 月 1 日
Thank you for answer. It works for me too.

サインインしてコメントする。

その他の回答 (1 件)

dpb
dpb 2023 年 8 月 1 日
It's possible to specify rows to load by address,but NOT by cell content.
You read the full file and then select the data desired by processing the content. In your case you'll have the first task to extract the numeric value of the first column and then find which row contains the range of interest...you may find something like
t=readtable('yourfile');
n=str2num(extract(t.Column1,digitsPattern));
a useful start; you can then locate which are within the desired bounds with a numeric comparison instead of text and locate those values in the file from which to select (it appears) the rows 1 after:1 before the succeeding value as containing the data of interest.
Attaching an actual (smallish) file would let folks illustrate more easily...
  4 件のコメント
Bartosz Pasek
Bartosz Pasek 2023 年 8 月 1 日
This is file have been downloaded from measuring device so there can be some errors and NaN values
Voss
Voss 2023 年 8 月 1 日
The NaN rows reported by readtable are actually rows with chars, which can be seen by using readcell.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by