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.

18 次查看(过去 30 天)
and i wrote volumes = data(:,3:4) is still giving me error
  2 个评论
John D'Errico
John D'Errico 2023-5-30
编辑:John D'Errico 2023-5-30
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.

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2023-5-30
编辑:DGM 2024-10-29
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 个评论
DGM
DGM 2024-10-29
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by