1

Data.xlsx is an excel file containing the data for 156 students. From cell 4 of the excel file, the 1st Student Number is displayed and if you increment by 7, you have the 2nd Student Number and so on up until the last cell 1094.

F = xlsread('Data.xlsx');

for ii =  4:7:1094
    studentNumbers = disp(F(ii)); 
end

but this gives me an error saying "Too many output arguments". However if I just specify disp(F(ii)), it does not give me any error and displays all the student numbers in order.

Is there a better way to do this so that I can assign all these Student Numbers into an array called studentNumbers?

2 Answers 2

1

If I understand correctly, you're trying to do the following:

studentNumbers = F(4:7:1094);
Sign up to request clarification or add additional context in comments.

Comments

0

disp is a function that displays the number on screen, not assigns it to another variable. If you want to assign you just use =. So your loop should be:

for ii =  4:7:1094
    studentNumbers = F(ii); 
end

Now, as @Sardar has pointed correctly, there is no need for a loop here, you can just assign all values in one command, using the vector 4:7:1094 as an indexing. As in his answer:

studentNumbers = F(4:7:1094);

But, if you can define the range of the data in Excel, then xlread lets you skip this assignment by setting the function to read a specific range, like:

sheet = 1; % if the data in in sheet 1
xlRange = 'D:D'; % if all the data is in column D
studentNumbers = xlsread('Data.xlsx',sheet,xlRange)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.