Why does the line plot depend on the generator type in a for loop ?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alexandre Kazantsev
el 8 de Mzo. de 2023
Comentada: Voss
el 15 de Mzo. de 2023
I have :
- a set of points in two dimensions given by their coordinates x_stations and y_stations;
- a set of couples of points given by the indices of point 1 (couples_st1) and point 2 (couples_st2) for each couple;
- a subset i_subset of those couples
I would like to plot i_subset graphically as lines linking point 1 and point 2 for each couple in the subset.
The problem : depending how I am looping on i_subset :
for i = i_subset
i_couple = i;
% some code...
% generate plot
% ouptut the plotted vectors
end
or
for i = 1:length(i_subset)
i_couple = i_subset(i);
% some code ...
% generate plot
% ouptut the plotted vectors
end
I get the same output of plotted vectors, but not the same plots. Why ?
A minimal example is enclosed with input data. Just run "main_minimal_example.m".
main_minimal_example
Thank you !
0 comentarios
Respuesta aceptada
Voss
el 8 de Mzo. de 2023
The i_subset passed in to make_line_plot.m is a column vector, and that is assigned to generator if mode == 1. Then generator is used in the for loop
for i_gen = generator
A for loop iterates over the columns of what you give it, so this loop iterates one time, with i_gen being generator.
When mode is 0, then generator is 1:length(i_subset), which is a row vector, and the for loop operates as intended (I assume).
To get the mode == 1 case to work like the mode == 0 case, one way would be to make the for loop iterate over elements of generator, as in:
for i_gen = generator(:).'
valArray — Create a column vector, index, from subsequent columns of array valArray on each iteration. For example, on the first iteration, index = valArray(:,1). The loop executes a maximum of n times, where n is the number of columns of valArray ]
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Descriptive Statistics and Visualization 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!

