How to read rows until I find blank row in csv file and copy to another cell?

조회 수: 7 (최근 30일)
Gopal Pande
Gopal Pande 2020년 9월 19일
댓글: Walter Roberson 2020년 9월 22일
I have .csv file with data.after few rows there are blank rows, blank row can be after 2 rows or after 5 rows or maybe after 150 rows it's not fixed. I wanted to copy data until find blank row and create seperate cell to use it further and do same with next rows of data until I find next blank row. Stuck with logic, tried using readmatrix(filename), tried detecting blank row from 'NaN' string Not able to solve this problem..

답변 (1개)

Walter Roberson
Walter Roberson 2020년 9월 19일
편집: Walter Roberson 2020년 9월 19일
d = readmatrix(filename)
mask = any(isnan(d), 2).';
starts = findstr([false, mask], [0,1]);
stops = findstr([mask, false], [1,0]);
blocks = arrayfun(@(s,e)d(s:e,:), starts, stops, 'uniform', 0);
  댓글 수: 6
Gopal Pande
Gopal Pande 2020년 9월 22일
New lines of code works better than previous.
But in blocks var blank row is getting copied into another cell, I want to copy data and not blank row which can be seperated/identified by NaN.
But thanks anyway, i am also debugging this code further to get what is intended...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by