Does anyone know what function to use to plot a space time graph?? (for the Nagel-Schreckneberg model, Graph displayed)
6 views (last 30 days)
Show older comments
Samuel Abera
on 4 Dec 2014
Commented: Star Strider
on 15 Dec 2014
Here, I am trying to redraw this graph on MATLAB. The dots represent 0 velocity while the integers represent velocity. Which functions shall I use to draw this graph?
0 Comments
Accepted Answer
Star Strider
on 5 Dec 2014
This brings me back to my FORTRAN days when we did such plots on the line printer!
The idea is to set up an array of ‘.’ and then overwrite numbers on the string array to do the plot:
s = repmat('.',1,72);
v = [20 5; 60 5; 72 5]; % Create Data
for k1 = 1:5
sd = s;
v(:,1) = rem(v(:,1)+1, 72);
sd(v(:,1)) = num2str(v(:,2),'%d');
fprintf(1, '%s\n', sd)
end
I created a ‘v’ matrix whose first column are the positions along the ‘sd’ vector, and whose second column are the velocities. The first line (‘sd’) resets the string for that loop iteration. The second line just increments ‘v’. (In your application, you will likely have calculated your own matrix of positions and velocities. This is just an illustration.) The next line (with num2str) prints the velocities at the correct position on the ‘sd’ vector. The last line prints it.
Run it to see what it does and how it works. This should get you started.
2 Comments
Star Strider
on 15 Dec 2014
My pleasure.
On Windows machines, the '\n' newline character string starts a new line. (Run my example code for an illustration.) See the documentation for fprintf under ‘Input Arguments’ -> ‘formatSpec’ -> ‘Control Characters’ for details.
I’ve addressed your second issue in my example code as well. See the ‘s’ string assignment at the top for details. If you want to print a period (.), it’s just another character, specifically '.', like any of the others.
By the way, my example code assumes a 72-character fixed-width-character line. That’s the reason for the repmat call.
More Answers (1)
Image Analyst
on 5 Dec 2014
How about fprintf()?
Or else scatter() or plot(), to do the dots, along with text() to do the numbers.
0 Comments
See Also
Categories
Find more on Title 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!