How do i plot two graphs in the same figure without it telling me that the vectors must be the same length?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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")
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');
0 commentaires
Réponse acceptée
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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Graphics Objects dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!