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

2 次查看(过去 30 天)
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 个评论
Henry
Henry 2025-2-14
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.
Walter Roberson
Walter Roberson 2025-2-14

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

请先登录,再进行评论。

回答(1 个)

BhaTTa
BhaTTa 2025-2-14
编辑:BhaTTa 2025-2-14
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.

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by