Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I have a matrix $(A_{10*10})$ in which each elements of matrix states the value of the function $y=f(x,y)$. Since, $y$ shows the enclosed area between two squares, so I don't have the value of these elements in this area. Now my question is that how can I plot the $y$ in termes of $x,y$ in 2D or 3D using matlab while I don't have the values of $y$ in $A(3:5,3:5)$? Thank you in advance.

share|improve this question
add comment

2 Answers

put your data instead of A matrice

 h = bar3(A);
 colormap jet

for change in color you can use this code :

 shading interp
 for i = 1:length(h)
     zdata = get(h(i),'ZData');

enter image description here

share|improve this answer
add comment

If you the values A(3:5,3:5) are undefined, set them to NaN and the plotting commands will ignore them. You can then use @AmirAlizadeh's approach with bar3, or draw an image with imagesc. The latter is perhaps less spectacular, but often clearer. In particular, with bar3 it would be hard to see the "hole" in x=3:5, y=3:5.

A=rand(10,10); % example data...
A(3:5,3:5) = NaN; % ...no data here
axis xy
xlabel 'x'
ylabel 'y'

enter image description here

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.