Interpolate positions between 2 matrix
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jose Martinez
le 18 Fév 2019
Commenté : Jose Martinez
le 19 Fév 2019
Hello,
If you see the picture below, I am representing dinamically the blue point with a matrix and imagesc function. What I would like to do is filling the gap bewteen points with more points, so the final graph woould look like a line.
An example how I am plotting the graph
% First point position in the matrix
0 0 0 1 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
% Next time period the matrix will have other values for the second "blue" point
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 1 0
% I would like to get automatically a matrix that interpolate between both "1" values and get something like below to draw a line,
0 0 0 1 0 0 0
0 0 0 0 1 0 0
0 0 0 0 1 0 0
0 0 0 0 0 1 0
I hope to make myself clear,
Thanks in advance!
0 commentaires
Réponse acceptée
Akira Agata
le 18 Fév 2019
How about the following?
% First point position in the matrix
M1 = [0 0 0 1 0 0 0;
0 0 0 0 0 0 0;
0 0 0 0 0 0 0;
0 0 0 0 0 0 0];
% Next time period the matrix will have other values for the second "blue" point
M2 = [0 0 0 0 0 0 0;
0 0 0 0 0 0 0;
0 0 0 0 0 0 0;
0 0 0 0 0 1 0];
[row,col] = find(M1 | M2);
row2 = (1:4)';
col2 = round(interp1(row,col,row2));
M3 = zeros(size(M1));
M3(sub2ind(size(M3),row2,col2)) = 1;
The result is:
>> M3
M3 =
0 0 0 1 0 0 0
0 0 0 0 1 0 0
0 0 0 0 1 0 0
0 0 0 0 0 1 0
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Interpolation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!