How to read alternate rows from an excel sheet?

7 ビュー (過去 30 日間)
Aravind Rajan AYAGARA
Aravind Rajan AYAGARA 2016 年 6 月 20 日
コメント済み: Shameer Parmar 2016 年 6 月 21 日
Hello, I am working with matlab to interpret data from excel sheets. Previously I used 'xlsread' function for reading data from a column for example * _ "t=xlsread(filename,sheet,'A2:A250')"_*.
Now I want to read data from alternate rows of a column regarding which I have no idea. I tried modifying my excel sheet but it did not work. Could anyone help me in figuring a way??

回答 (2 件)

Guillaume
Guillaume 2016 年 6 月 20 日
Yes, as per Shameer's answer, xlsread does not support reading non-continuous ranges, so you'll have to read the whole range at once.
It's just a matter of simple indexing to remove alternate rows. Do not use a loop for that:
t = xlsread(filename,sheet,'A2:A250')
toddrows = t(1:2:end, :)
tevenrows = t(2:2:end, :)
  1 件のコメント
Aravind Rajan AYAGARA
Aravind Rajan AYAGARA 2016 年 6 月 20 日
Voila! this method Works!!!
Thank you Mr. Guillaume

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


Shameer Parmar
Shameer Parmar 2016 年 6 月 20 日
Hello Aravind,
As per my knowledge, in xlsread, there is no such facility to fetch alternate rows of column.
You can do one thing.. after calculating value of t..
do this..
count = 1;
for i = 1:length(t)
if rem(i,2)~=0
new_t{count} = t{i};
count++;
end
end
  2 件のコメント
Aravind Rajan AYAGARA
Aravind Rajan AYAGARA 2016 年 6 月 20 日
Thenk you for your reply, the compiler shows an error saying 'Expression or statement is incomplete or incorrect' in 'count++'
Shameer Parmar
Shameer Parmar 2016 年 6 月 21 日
ohh.. I checked and I made the changes as follows...
count = 1;
for i = 1:length(t)
if rem(i,2)~=0
new_t(count) = t(i);
count = count + 1;
end
end

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

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by