- 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
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
How can I tell if this is stored as a vector?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Stephen23
am 14 Feb. 2018
Bearbeitet: Stephen23
am 14 Feb. 2018
"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 Kommentare
Rachel Dawn
am 15 Feb. 2018
1 Kommentar
Stephen23
am 15 Feb. 2018
@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.
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!