How to select every second number from a file of numbers separated by a comma

조회 수: 1 (최근 30일)
Hello
we were given an assignment in MATLAB at our university.
I have no programming experience with MATLAB whatsoever and now we are required to complete this seemingly daunting assignment.
Could anyone please explain to me where should I even start in completing this assignment. MATLAB code is essentially like reading chinese.
I am currently stuck at writting the code for selecting every second number from a text file full of numbers separated by a comma. The tutor at UNI advises to use a for loop.
I linked the pdf of the assignment and the text document with the numbers. We are supposed to select every second number from a row of 4 numbers. For example: 1 2 3 4 1 2 3 4 1 2 3 4... and every number marked by 2 is the number we have to select.
I have esentially no idea what to do.
Thanks in advance

채택된 답변

Star Strider
Star Strider 2020년 10월 25일
I looked at ‘UE1.txt’ and I initially could not make any sense out of it. It’s apparently supposed to be a multi-channel recording, however it imports as a (1x57604) vector.
Guessing as to its structure, this will parse it into what appear to be the appropriate vectors:
D = load('UE1.txt'); % Data Vector
Dm = reshape(D, 4, []); % ‘D’ Matrix
figure
for k = 1:3
subplot(3,1,k)
plot(Dm(1,:), Dm(k+1,:))
title(sprintf('Channel %d',k+1))
grid
xlim([0 10])
end
I normally do not provide excessive amounts of assistance for homework assignments, however if you have not been introduced to the requisite functions (such as reshape) for this, some assistance is necessary. The first row of the signal matrix ‘Dm’ after using the reshape call appears to be the time base, and the others are signals. You can figure out the sampling frequency easily enough from the time vector ‘DM(1,:)’.
I have plotted the signals as appear to be appropriate. I leave the rest to you!
  댓글 수: 5
Alex Dimko
Alex Dimko 2020년 10월 25일
Thanks. You already helped me way more than my lecture.

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

추가 답변 (1개)

David Hill
David Hill 2020년 10월 25일
a=reshape(load('UE1.txt'),4,[])';
yourNumbers=a(:,2);

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by