Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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');

Réponse acceptée

Torsten
Torsten le 7 Déc 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 commentaires
Wouter
Wouter le 8 Déc 2022
I did it wrong. Sorry man, thank you for the solution now it works!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Tags

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by