Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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|cite|improve this question

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|cite|improve this answer

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; % data here
axis xy
xlabel 'x'
ylabel 'y'

enter image description here

share|cite|improve this answer

To see negative values during X-Y-View (view similar to imagesc) you can define a function like this to change the color of the bars corresponding to their height:

function make_bar3_scaled_color(h) %MAKE_BAR3_SCALED_COLOR changes the color of the bars in a BAR3 plot %corresponding to their heigths.

for i = 1:length(h)
    zdata = get(h(i),'ZData');
    size_zdata = size(zdata);
    %zdata = ones(size_zdata);
    for j=0:6:(size_zdata(1)-6)
        akt_data = zdata(j+1:j+6,:);
        [max_akt_data max_pos] = max(abs(akt_data(:)));
        zdata(j+1:j+6,:) = akt_data(max_pos);


share|cite|improve this answer

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.