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

2 visualizaciones (últimos 30 días)
Rafael
Rafael el 12 de Abr. de 2024
Editada: the cyclist el 12 de Abr. de 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]')

Respuesta aceptada

the cyclist
the cyclist el 12 de Abr. de 2024
Editada: the cyclist el 12 de Abr. de 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.

Más respuestas (0)

Categorías

Más información sobre Discrete Data Plots en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by