TASK Create a variable volumes that contains the last two columns of data. You can see the size of data in the output pane to the right of your screen.
15 views (last 30 days)
Show older comments
and i wrote volumes = data(:,3:4) is still giving me error
2 Comments
John D'Errico
on 30 May 2023
Edited: John D'Errico
on 30 May 2023
The line you wrote SHOULD put columns 3 and 4 into the array volumes. That it generates an error just means you did something we are not told.
When you get an error, show the ENTIRE error. Don't just tell us that something is still giving an error. We cannot see your screen, and we certainly cannot see into your computer.
Paste in the error message, the ENTIRE error message. So everything in red.
Answers (1)
Image Analyst
on 30 May 2023
Edited: DGM
on 29 Oct 2024
Is data a 3-D array? What does this show"
whos data
If data is a 3-D array you need to do
volumes = data(:, 3:4, :)
If data is a 2-D array, then your code would have worked.
1 Comment
DGM
on 29 Oct 2024
FWIW, the exercise uses a 7x4 array. The evaluator will accept anything which produces the expected output, so
% the given answer works fine
volumes = data(:, 3:4)
will work, just the same as anything equivalent for the given input:
% the intended answer
volumes = data(:, end-1:end)
% it's not necessary, but these are also accepted
volumes = data(:, 3:4, :)
volumes = data(:, end-1:end, :)
% so is something unnecessarily complicated
col = size(data,2) + [-1 0];
volumes = data(:,col)
I did actually test those.
I'm with John on this one. There is (was) something else going on. It might not even be an issue with the code at all, so I don't expect that any error message actually occurs in the editor. I know the onramp interface bugs out sometimes and refuses to accept correct answers. I had to reload it a couple times before it would even let me type in the editor, and it doesn't even load at all in Firefox anymore, so maybe reloading or trying a different browser is at least an attempt at troubleshooting.
See Also
Categories
Find more on Whos 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!