- any expression will display its output when it does NOT have a trailing semicolon.
- calling disp with some input data
- calling fprintf with some input data
- error or warning calls.
Info
此问题已关闭。 请重新打开它进行编辑或回答。
How can I tell if this is stored as a vector?
1 次查看(过去 30 天)
显示 更早的评论
Basically, I created a function, which contains the following (along with some other stuff):
Lala= myfunction(a,b,n)
...
LaLa=zeros(1,n);
index= 3:n
Lala(index)= Lala(index-1) + Lala(index-2);
How can I tell if I'm just "displaying the series elements as I calculate them" or if I'm "storing and displaying the series as a vector"?
This is a homework assignment where they asked us to first display the first n numbers of the series, and then it says to 'modify the function' to return the series as a vector.
I've tried doing this: Lala= [1:length(n)]; (instead of the zeros function).
However, I don't know how to tell if Lala is a vector or not? It displays the same either way: 0 1 1 2
0 个评论
回答(2 个)
Stephen23
2018-2-14
编辑:Stephen23
2018-2-14
"Displaying" in this context typically means to print some data to the command window. There are several ways to achieve this, such as:
So to fulfill the first part of the assignment "...first display.." you would need something like this:
function myfunction(a,b,n) % no output argument!
...
LaLa = zeros(1,n);
index = 3:n;
Lala(index)= Lala(index-1) + Lala(index-2) % no semicolon!
and for the second part you can add the semicolon (so it does NOT display any more) and add the output argument so that it returns those values:
function LaLa = myfunction(a,b,n) % with output argument!
...
LaLa = zeros(1,n);
index = 3:n;
Lala(index)= Lala(index-1) + Lala(index-2); %semicolon!
"However, I don't know how to tell if Lala is a vector or not?"
A vector has size 1xN or Nx1. According to that LaLa is a vector, because that is how you defined it using zeros(1,n). If n is a scalar then 1:length(n) is also a scalar (you did not tell us what size n is).
0 个评论
Rachel Dawn
2018-2-15
1 个评论
Stephen23
2018-2-15
@Rachel Dawn: I hope that it helped. You should also accept the answer that best helped resolve your original question: this tells other users that your question has been resolved.
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!