From: kelc garing on
Ok so in class we have to write a code
-write a function that takes a n by n matrix containing 0s and 1s and uses Matlabs image command to display that board in black and white
Help this is as far as i got

function draw_board(matrix)
[n,m]=size(matrix);
for a=1:n;
for b=1:m;
plot(value(a,b))
end
end

help!
From: Nathan on
On Apr 9, 1:33 pm, "kelc garing" <dunkitspikei...(a)msn.com> wrote:
> Ok so in class we have to write a code
> -write a function that takes a n by n matrix containing 0s and 1s and uses Matlabs image command to display that board in black and white
> Help this is as far as i got
>
> function draw_board(matrix)
> [n,m]=size(matrix);
> for a=1:n;
>     for b=1:m;
>         plot(value(a,b))
>     end
> end
>
> help!

And what do you need help with exactly?
Where are you stuck?
What do you think you need to do next?

-Nathan
From: kelc garing on
ok i just dont know aht else to do
i added some more (below)
can you tell me where i am going wrong or what i should add?

function draw_board(matrix)
[n,m,value]=size(matrix);
for a=1:n;
for b=1:m;
if (a,b,:)==1
(:,:,:)=255;
else if (a,b,:)==0;
(:,:,:)=0;
end
end
end
image(matrix)
From: Nathan on
On Apr 9, 1:44 pm, "kelc garing" <dunkitspikei...(a)msn.com> wrote:
> ok i just dont know aht else to do
> i added some more (below)
> can you tell me where i am going wrong or what i should add?
>
> function draw_board(matrix)
> [n,m,value]=size(matrix);
> for a=1:n;
>     for b=1:m;
>         if (a,b,:)==1
>             (:,:,:)=255;
>         else if (a,b,:)==0;
>             (:,:,:)=0;
>         end
>     end
> end
> image(matrix)

Good, you noticed the error of using "plot" rather than "image".

How do you view one value of a matrix?
Note that "(a,b,:) == 1" is improper syntax.
What do you expect to see from "(a,b,:)"?

Once you get that minor problem sorted out, you have the problem
pretty much solved.

By the way: Is the matrix passed in 2 dimensional, or is it of higher
dimensions?
The way you have your code right now, as close as it may be, almost
treats the matrix as a 3-dimensional array.

-Nathan
From: kelc garing on
im not sure i see whats wrong with (a,b,:)==0
and i thinks it supposed to be a 3d matrix because then image can be used