Issues making the table and plot output properly

3 visualizaciones (últimos 30 días)
Michael spillane
Michael spillane el 3 de Feb. de 2018
Comentada: Image Analyst el 4 de Feb. de 2018
Question is: Write a script file that accepts each of the four vectors as inputs. The script file should plot the data on three different graphs in the same window. The function should also display the data in a table with the following form (including the header). In this problem you’re required to use fprintf to generate the table below.
Time (s) A1 (m/s2) A2 (m/s2) A3 (m/s2)
0 0 0 0
5 7 10 9
10 11 15 13
15 19 21 17
20 15 16 22
25 14 11 25
30 17 13 21
My code: t = input('Input the initial and final time(X is start Y is end), ex:[X:5:Y]');
a1 = input('Enter A1 data ex: [0 7 11 ...]');
a2 = input('Enter A2 data ex: [0 7 11 ...]');
a3 = input('Enter A3 data ex: [0 7 11 ...]');
plot(t,a1);
hold on;
plot(t,a2);
hold on;
plot(t,a3);
hold off;
legend('A1=a1','A2=a2','A3=a3');
fprintf('%6s %6s %6s %6s\n','Time(s)','A1(m/s2)','A2(m/s2)','A3(m/s2)');
fprintf('%.3f \t %.3f \t %.3f \t %.3f\n',t,a1,a2,a3);
I am getting an incorrect plot and table, all mismatched numbers. Debugging while I wait for an answer but I feel someone else will be able to recognize the error faster than I can.
Thanks in advance ;)
Edit: This is the output I get. I feel there is an issue with the way I had the information inputted, but I havent been able to figure out how to have it print properly:
Time(s) A1(m/s2) A2(m/s2) A3(m/s2)
0.000 5.000 10.000 15.000
20.000 25.000 30.000 0.000
7.000 11.000 19.000 15.000
14.000 17.000 0.000 10.000
15.000 21.000 16.000 11.000
13.000 0.000 9.000 13.000
17.000 22.000 25.000 21.000
  1 comentario
Michael spillane
Michael spillane el 3 de Feb. de 2018
The plot isnt the issue, it appears to be the way my input is formatted, as can be seen in the table on the bottom

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 3 de Feb. de 2018
"three different graphs in the same window." could mean
subplot(2,2,1);
plot(.....
subplot(2,2,2);
plot(.....
subplot(2,2,3);
plot(.....
To get a table, you should use the uitable() function.
  8 comentarios
Stephen23
Stephen23 el 4 de Feb. de 2018
Editada: Stephen23 el 4 de Feb. de 2018
fprintf('%11.3f %11.3f %11.3f %11.3f\n',[t,a1,a2,a3].');
Image Analyst
Image Analyst el 4 de Feb. de 2018
That's because my a1, etc. were column vectors and your were row vectors because of the different ways we created the vectors. (I was lazy and didn't want to type in all that stuff while I was developing the code for you.)

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by