Borrar filtros
Borrar filtros

Unrecognized function or variable 'doPlot'.

10 visualizaciones (últimos 30 días)
Pawan
Pawan hace alrededor de 20 horas
Respondida: Umar hace alrededor de 2 horas
if doPlot == 1
plot(density)
title("Sample Densities")
xticklabels(element)
ylabel("Density (g/cm^3)")
end
Unrecognized function or variable 'doPlot'.

Respuesta aceptada

Umar
Umar hace alrededor de 1 hora

Hi @Pawan,

To resolve the error regarding the undefined variable doPlot, you need to define it before the plotting section. Additionally, make sure that the variables density and element are also defined. Here’s a corrected version of your code:

% Define the variables doPlot = 1; % Set to 1 to enable plotting density = [2.7, 7.85, 1.0]; % Example density values in g/cm^3 element = {'Aluminum', 'Iron', 'Water'}; % Corresponding element names

% Plotting section
if doPlot == 1
  plot(density, '-o') % Added marker for better visibility
  title("Sample Densities")
  xticks(1:length(element)) % Set x-ticks to match the number of elements
  xticklabels(element)
  ylabel("Density (g/cm^3)")
end

Please see attached plot.

Hope this answers your question.

Más respuestas (1)

Star Strider
Star Strider hace alrededor de 20 horas
You have to provide a value for ‘doPlot’ earlier in the code.

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by