Filter löschen
Filter löschen

How do i plot two graphs in the same figure without it telling me that the vectors must be the same length?

1 Ansicht (letzte 30 Tage)
Sorry for inputting my entire code but i am new to matlab.
I am trying to get two Voltages (Spanning & Spanning_fit) into the same graph with time (Tijd) on the x axis.
But it won't let me and gives me the error: 'vectors must be the same length'. I know they are not but i am totally new to this.
Any ideas? Sorry if my question is really unclear.
load ("coltdata_busdaq_personalised.mat")
Error using load
Unable to find file or directory 'coltdata_busdaq_personalised.mat'.
A = data;
Tijd = A (2:21838,1);
Spanning = A (2:21838,2);
Stroom = A (2:21838,3);
Snelheid_ms = A (2:21838,4);
Snelheid_kmh = A (2:21838,5);
Kracht = A (2:21838,6);
Efficientie = A (2:21838,7);
figure;
subplot(3,2,1);
plot(Tijd,Spanning,'r'); hold on
xlabel('Tijd(s)')
ylabel('Spanning(V)')
grid;
subplot(3,2,2);
plot(Tijd, Stroom,'g'); hold on
xlabel('Tijd(s)')
ylabel('Stroom(A)')
grid;
subplot(3,2,3);
plot(Tijd,Snelheid_ms,'b'); hold on
xlabel('Tijd(s)')
ylabel('Snelheid(m/s)')
grid;
subplot(3,2,4);
plot(Tijd, Snelheid_kmh,'y'); hold on
xlabel('Tijd(s)')
ylabel('Snelheid(km/h)')
grid;
subplot(3,2,5);
plot(Tijd,Kracht,'m'); hold on
xlabel('Tijd(s)')
ylabel('Kracht(N)')
grid;
subplot(3,2,6);
plot(Tijd, Efficientie,'k');
xlabel('Tijd(s)')
ylabel('Efficientie(%)')
grid;
coefficients = polyfit(Stroom,Spanning,1);
figure;
scatter(Stroom,Spanning,'filled'); hold on
Spanning_fit = Stroom*coefficients(1)+coefficients(2);
plot(Stroom,Spanning_fit,'k');
title('Accuspanning tegen de accustroom');
xlabel('Accustroom(A)');
ylabel('Accuspanning(V)');
legend('Ruwe data','Benadering')
grid;
figure;
scatter(Stroom,Spanning_fit); hold on
Stroom = 0:5:140;
Spanning_fit = Stroom*coefficients(1)+coefficients(2);
plot(Stroom,Spanning_fit,'k');
title('De fit tegen de stroom')
xlabel('Accustroom(A)');
ylabel('Spanning(V)');
legend('Meetdata','Benadering')
grid;
figure;
plot(Tijd,Spanning); hold on
plot(Tijd,Spanning_fit,'k');

Akzeptierte Antwort

Torsten
Torsten am 7 Dez. 2022
Use
figure;
scatter(Stroom,Spanning_fit); hold on
Stroom1 = 0:5:140;
Spanning_fit = Stroom1*coefficients(1)+coefficients(2);
plot(Stroom1,Spanning_fit,'k');
title('De fit tegen de stroom')
xlabel('Accustroom(A)');
ylabel('Spanning(V)');
legend('Meetdata','Benadering')
grid;
figure;
plot(Tijd,Spanning); hold on
plot(Tijd,Stroom*coefficients(1)+coefficients(2),'k');
instead of
figure;
scatter(Stroom,Spanning_fit); hold on
Stroom = 0:5:140;
Spanning_fit = Stroom*coefficients(1)+coefficients(2);
plot(Stroom,Spanning_fit,'k');
title('De fit tegen de stroom')
xlabel('Accustroom(A)');
ylabel('Spanning(V)');
legend('Meetdata','Benadering')
grid;
figure;
plot(Tijd,Spanning); hold on
plot(Tijd,Spanning_fit,'k');
  3 Kommentare

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by