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

11 views (last 30 days)
Alex Dimko on 25 Oct 2020
Commented: Star Strider on 25 Oct 2020
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.

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!

Star Strider on 25 Oct 2020
My pleasure!
I woud begin with what David Hill advised, as well as Getting Started, and look up the functions, starting with reshape (that I linked to here, so click on the link to bring up the associated documentation). MATLAB has become a huge programming environment (when I first began to use it in the early 1990s all the documentation was in a few hardopy manuals), so search the online documentation for the information you need to use the core functions (such as reshape) and necessary Toolbox functions, if you have them and need their functions.
Alex Dimko on 25 Oct 2020
Thanks. You already helped me way more than my lecture.
Star Strider on 25 Oct 2020
My pleasure!

David Hill on 25 Oct 2020
yourNumbers=a(:,2);