dot Indexing is not supported for variables of this type error on a scatterplot

Im new to Matlab and cnat figure out what is wrong with this code, I literally copied someones code down word for word, I keep getting the arror but they dont. if I comment out the scatter_2 and everything below it the code works but once I add it back in the error shows up. I dont get why I can use dot indexind on the first section but not on the second.
% Step 8: Scatter plot for the correlation between Beam Length and Yield Strength
scatter(beam_data.Length, beam_data.YieldStrength, 100, "b.")
xlabel('Beam Length (Meters)')
ylabel('Yield Strength (Newtons')
title('Beam Length and Strength Correlation')
hold on
scatter_2 = scatter(total_over_stressed_beam.Length, total_over_stressed_beam.YieldStrength, 10, "red", 'filled')
legend(scatter_2, 'Overstressed')
hold off

5 comentarios

Immediately before running these lines of code, run this command and show us the output:
whos
More likely than not, whoever wrote the code that you copied defined their variables differently from how you've defined yours. For example, if beam_data was a struct array asking for its Length field may work (if it has such a field):
beam_data = struct('Length', 42, 'Width', 99);
beam_data.Length
ans = 42
but if it was a plain numeric array it wouldn't.
beam_data = 1:10;
beam_data.Length
Dot indexing is not supported for variables of this type.
whos
Name Size Bytes Class Attributes
Saftey_factor 100x1 800 double
beam_data 100x7 8137 table
over_stressed 100x1 100 logical
over_stressed_beam_total 1x1 8 double
over_stressed_beams 11x4 2133 table
percentage_over_stressed 1x1 8 double
total_over_stressed_beam 1x1 8 double
we worked together on the project so everythin else should be the same.
Please show us the complete error message. This means all of the red text.
Step 8: Scatter plot for the correlation between Beam Length and Yield Strength
scatter(beam_data.Length, beam_data.YieldStrength, 100, "b.")
xlabel('Beam Length (Meters)')
ylabel('Yield Strength (Newtons')
title('Beam Length and Strength Correlation')
hold on
scatter_2 =scatter(over_stressed_beam_total.Length, over_stressed_beam_total.YieldStrength, 10, "red", 'filled')
legend(scatter_2, 'Overstressed')
hold off
Dot indexing is not supported for variables of this type.

over_stressed_beam_total is a double, not a struct or table. You cannot use dot indexing on a double. You need to figure out how it got to be a double instead of a struct or table

Iniciar sesión para comentar.

Respuestas (1)

BhaTTa
BhaTTa el 14 de Feb. de 2025
Editada: BhaTTa el 14 de Feb. de 2025
Hey @Henry, I understand that you are facing error in scatter_2 plot, specifically with using dot indexing on total_over_stressed_beam, follow the below steps to troubleshoot the issue:
  1. Ensure that total_over_stressed_beam is defined before you attempt to use it. It should be a structure or table with fields Length and YieldStrength.
  2. Double-check the spelling of total_over_stressed_beam and its fields. MATLAB is case-sensitive, so any mismatch will lead to errors.
  3. You can verify that total_over_stressed_beam is indeed a structure or table by using the whos command or class function.

1 comentario

I gave all those a try and the error still appears, could there be any other fixes?

Iniciar sesión para comentar.

Categorías

Más información sobre Data Distribution Plots en Centro de ayuda y File Exchange.

Productos

Versión

R2024b

Etiquetas

Preguntada:

el 14 de Feb. de 2025

Comentada:

el 14 de Feb. de 2025

Community Treasure Hunt

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

Start Hunting!

Translated by