How to fix "Error using /, Matrix dimensions must agree"

2 vues (au cours des 30 derniers jours)
Rafael
Rafael le 12 Avr 2024
Modifié(e) : the cyclist le 12 Avr 2024
I'm just tryng to create a simple graph to display how some values change depedning on another variable, but for some reason it is not working. I do not know what to do.
Here is the code:
Fw=195*9.81;
CD=2.125;
BD_var = 0.1:0.01:CD;
MinFh=(Fw*CD*cosd(45))/(BD_var);
MaxFh=(Fw*CD*cosd(0))/(BD_var);
figure(2)
ax = axes;
plot(BD_var,MinFh)
title('Minimum Force on HC for Varying Distances')
axis ([0 inf 0 inf])
xlabel('Distance [m]')
ylabel('Force [N]')

Réponse acceptée

the cyclist
the cyclist le 12 Avr 2024
Modifié(e) : the cyclist le 12 Avr 2024
Take a look at the documentation on Array vs. Matrix Operations.
I used element-wise division (using ./ rather than /) in your code:
Fw=195*9.81;
CD=2.125;
BD_var = 0.1:0.01:CD;
MinFh=(Fw*CD*cosd(45))./(BD_var);
MaxFh=(Fw*CD*cosd(0))./(BD_var);
figure(2)
ax = axes;
plot(BD_var,MinFh)
title('Minimum Force on HC for Varying Distances')
axis ([0 inf 0 inf])
xlabel('Distance [m]')
ylabel('Force [N]')
You might be interested in the free MATLAB Onramp tutorial.

Plus de réponses (0)

Catégories

En savoir plus sur Discrete Data Plots dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by