how to use hold on for two different imagesc plots

33 views (last 30 days)
I have a matrix like below and want to find imagesc(); hold on; imagesc();
t1 = [1 2 3 6 7];
E1 = [-0.00660786358639598 0.0777130350470543 0.126017674803734 0.189686760306358 0.262237429618835]
fx1 = [5.6157475 5.5697780 5.5289726 5.4838061 5.4012895
5.5453439 5.4993744 5.5572557 5.5120893 5.5418348
5.6823254 5.6363554 5.5536976 5.5085306 5.4978499
5.3619905 5.3160210 5.6277847 5.5826178 5.5214615
5.5157361 5.4697666 5.4811044 5.4359379 5.4907508]
t2 = [4 5 8 9 10];
E2 = [1.39749240875244 1.44495928287506 1.49170267581940 1.53834557533264 1.58445668220520];
fx2 = [5.5889688 5.5429993 5.5185990 5.4734325 5.4242330
5.4456487 5.3996792 5.7355318 5.6903653 5.4353333
5.7974424 5.7514729 5.3296890 5.2845225 5.5169930
5.6018438 5.5558739 5.2609043 5.2157373 5.5721898
5.5223360 5.4763665 5.6631050 5.6179385 5.3880172]
imagesc(E1,t1,fx1); % shading flat
hold on;
imagesc(E2,t2,fx2); % shading flat
view([270 90]);
however, the o/p to this imagesc plot is very vague with misoverlaps.
Can anyone please help.

Answers (1)

Walter Roberson
Walter Roberson on 16 Feb 2021
Edited: Walter Roberson on 16 Feb 2021
t1 = [1 2 3 6 7];
E1 = [-0.00660786358639598 0.0777130350470543 0.126017674803734 0.189686760306358 0.262237429618835];
fx1 = [5.6157475 5.5697780 5.5289726 5.4838061 5.4012895
5.5453439 5.4993744 5.5572557 5.5120893 5.5418348
5.6823254 5.6363554 5.5536976 5.5085306 5.4978499
5.3619905 5.3160210 5.6277847 5.5826178 5.5214615
5.5157361 5.4697666 5.4811044 5.4359379 5.4907508];
t2 = [4 5 8 9 10];
E2 = [1.39749240875244 1.44495928287506 1.49170267581940 1.53834557533264 1.58445668220520];
fx2 = [5.5889688 5.5429993 5.5185990 5.4734325 5.4242330
5.4456487 5.3996792 5.7355318 5.6903653 5.4353333
5.7974424 5.7514729 5.3296890 5.2845225 5.5169930
5.6018438 5.5558739 5.2609043 5.2157373 5.5721898
5.5223360 5.4763665 5.6631050 5.6179385 5.3880172];
imagesc(E1,t1,fx1); % shading flat
hold on;
imagesc(E2,t2,fx2); % shading flat
xlim([-.1 1.7]); ylim([0 11])
view([270 90]);
Remember, when you use hold on, you "hold" the automatic determination of the axes limits according to the plotted data.
  2 Comments
Megha
Megha on 16 Feb 2021
Walter Roberson Exactly, this is what i am getting, why the lower part do not show white space (gap) at x=4 and x=5 like how it does beyond x=7? Similarly why upper part do not show white space (gap) at x=6 and x=7??
Walter Roberson
Walter Roberson on 16 Feb 2021
The current documentation for the x and y coordinates only defines passing a scalar or a two-element vector for position.
Historically there is documentation somewhere that if you pass in a vector of values with more than one element, then it uses the first and last elements of the vectors and ignores the rest.
You do not pass in coordinates for the center of each pixel, only information about the centers of the lower left and upper right corners. MATLAB has never permitted you to pass in a vector of values for the centers of each column individually.
What MATLAB does offer is pcolor(), which permits you to pass in positions about the vertices of each face of a surface, with the color of the face being taken by interpolation from the data associated with its four corners. pcolor() however does not put in gaps: it fills the color in for the entire face rectangular face.

Sign in to comment.

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!