Using variable as part of name to extract sequentially named columns from imported table

Hi everyone,
As part of a program I'm trying to graph multiple sets of data from an imported table from an exel file, "data". These data sets are sequentially titled (Force, Force_1, Force_2, etc.), and I'm trying to graph everything using a for loop, and the iterating variable as part of the coloumn. The columns aren't sequential in the table, so using the name appears to be the most efficient choice. Does anyone have advice on the best way to do this? Thanks!
disp("Graphing start")
for i=1:wmod
force=data.Force_"(wmod)";
stroke=data.Stroke_"(wmod)";
plot(stroke,force)
hold on
end

 Accepted Answer

for i = 1:wmod
force = data.("Force_" + i);
stroke = data.("Stroke_" + i);
plot(stroke, force, 'displayname', string(i));
hold on
end
legend show

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Release

R2022a

Asked:

on 22 Mar 2025

Commented:

on 23 Mar 2025

Community Treasure Hunt

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

Start Hunting!