Select specific elements in a cell

조회 수: 2 (최근 30일)
Kenan Hoyt
Kenan Hoyt 2014년 6월 24일
편집: dpb 2014년 6월 25일
Hello, this is a very frustrating problem for me
I am using a loop that reads text lines from a data file using fgetl , such a line could look like this (there are many lines):
60 233 24 53 26 53 234 32
And could continue forever. I am trying to create a vector of every 1st value and a separate vector for every 2nd value, which is possible, but the following elements come in pairs . To illustrate:
aline = a b e f e f e f e f e f e f e f ...
anotherline = a b e f e f e f e f e f e f ...
so on ...
I am trying to make a cell for the e and a separate cell for f values, but cannot 'select' them in order to do so. How can you do this? I have tried playing with rem(1:len,2) == 1 (len = length of vector) to select every "odd" or "even" number, but it doesn't work as u want it to, as you cannot do the following.
x = rem(1:25,2) == 0;
vector(x);
What am i missing?
  댓글 수: 6
Sean de Wolski
Sean de Wolski 2014년 6월 25일
dpb, you can accept your own answer you just don't get reputation points for it. He can't accept the answer because it's in the comments not the answer box.
dpb
dpb 2014년 6월 25일
Oh, ok...I am now informed on the "ACCEPT" rules--was "underneath the impression" couldn't actually accept one's own.
I added a full solution w/o the line-by-line loop as an additional answer that should solve the problem--if not, hopefully Kenan will come back and explain where there's a problem needing fixup.

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

채택된 답변

dpb
dpb 2014년 6월 25일
편집: dpb 2014년 6월 25일
Instead of reading the file line-by-line and "growing" the arrays incrementally, try something like
x=textread('filename');
WW=x(:,1);
DD=x(:,2);
tt=x(:,3:2:end);
CC=x(:,4:2:end);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Historical Contests에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by