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

1 view (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 25 Oct 2020
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 Comments

Sign in to comment.

More Answers (1)

David Hill
David Hill on 25 Oct 2020
a=reshape(load('UE1.txt'),4,[])';
yourNumbers=a(:,2);

Categories

Find more on Performance and Memory in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!