Random color matrix in matlab

I would like to generate a matrix of random color blocks -- 10 by 10 pixel blocks of random colors -- such as:


So far, I have generated random numbers and enlarged the matrix with kron:



I = kron(randn([10 10]), ones(10));

I would like to add random colors to this, but:

I = kron(randn([10 10 3]), ones(10));


error: invalid conversion of NDArray to Matrix

How can I generate a matrix of random color blocks?

This is for use with Psychtoolbox-3 (DrawTexture does not seem able to scale up a 10x10 random color matrix to 100x100 without interpolation).


You might as well generate the matrix directly:

    R = rand(10,10,3);

In order to create a block matrix, use imresize:

    Rb = imresize(R,10,'nearest');

This is the way I usually do something similar, in case it helps:

R = rand(10,10);
colormap jet

Where the colormap can be changed to any of Matlab's presets, or your own, to reflect the value in the matrix.

The proper solution is to switch the interpolation algorithm for the particular texture.

Behind the scenes Psychtoolbox uses OpenGL, which allows you to fiddle with raw OpenGL commands between MakeTexture and DrawTexture.

roughly, from memory. Fill in the "blanks"


Need Your Help

What is the best way to return an error from a function when I'm already returning a value?

c return

I wrote a function in C that converts a string to an integer and returns the integer. When I call the function I also want it to let me know if the string is not a valid number. In the past I retur...

Live streaming from iOS to Wowza and viceversa

ios objective-c streaming live wowza

I need to know something more about the integration of Wowza with iOS. I need to publish the live camera streaming to Wowza from the iPhone and also to see live streaming from the server. There are