Skipping a line no delimiters in an array

7 ビュー (過去 30 日間)
Abbey Stock
Abbey Stock 2021 年 10 月 26 日
編集済み: Scott MacKenzie 2021 年 10 月 29 日
Hi,
I have read in an excel file of data into an array and all the data has the same number of delimiters per line. I am trying to seperate this data by the "," delimiter which is already in the file which is no problem. However, every now and then there will be a row of just text with 0 delimiters that I would like to skip past when reading the array i have read the file into. These rows are just title rows explaining whats below, but I do not need these in the final array, just the raw data.
How can I skip past these rows? The row numbers for these rows will vary for each file i read in, so I am trying to avoid a solution where i skip past a line number.
Thank you in advance for your help
  3 件のコメント
Ive J
Ive J 2021 年 10 月 26 日
Can you provide a working example?
Walter Roberson
Walter Roberson 2021 年 10 月 26 日
We need to know if this is a text file (such as .csv) or a .xlsx file.

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

採用された回答

Scott MacKenzie
Scott MacKenzie 2021 年 10 月 26 日
編集済み: Scott MacKenzie 2021 年 10 月 29 日
From your comment, it seems you are working with an Excel file, as opposed to comma-delimited text file.
Given this and your description of the organization of the data, here's one approach. Using the example data in test2.xlsx (attached)...
the following script reads all the data, then removes the non-numeric rows:
M = readmatrix('test2.xlsx');
M(isnan(M(:,1)),:) = []
M = 4×5
1 2 3 4 5 6 7 8 9 10 55 66 77 88 99 98 76 54 32 1
  3 件のコメント
Walter Roberson
Walter Roberson 2021 年 10 月 29 日
you will need to readcell and filter the results
Scott MacKenzie
Scott MacKenzie 2021 年 10 月 29 日
編集済み: Scott MacKenzie 2021 年 10 月 29 日
@Abbey Stock ok, sure. I just altered my solution to work with any number of title lines in different rows.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by