how to craete a matrix with desired elements

4 visualizzazioni (ultimi 30 giorni)
in case of magic(n) and rand(n) an n by n matrix is created wit magic and pseudorandom elements respectively ,
how i can create a matrix of my choice(rows and col.) and with user defined elements in it .

Risposta accettata

Matt Fig
Matt Fig il 17 Ott 2012
Modificato: Matt Fig il 17 Ott 2012
Many ways! What do you have in mind exactly?
In the most general form:
function A = makematrix()
% Help user create an array.
% Note, error checking not written yet.
R = input('Enter the number of rows: ');
C = input('Enter the number of columns: ');
A = zeros(R,C);
for ii = 1:R
for jj = 1:C
S = sprintf('Enter element at (%i,%i): ',ii,jj);
A(ii,jj) = input(S);
end
end
  2 Commenti
MANJUNATH
MANJUNATH il 17 Ott 2012
i have a 32 by 32 pixels, i have to address(using binary values) each pixel , obtain their output and display as an image (gray scale ) for which can use imshow , actually image has to contain 32 by 32 pixels
i am finding it difficult in addressing , i use bvdata=logical[0 0 0 0 0 0 0 0 0 0 ] putvalue=(dio,bvdata) to address each pixel , so similarly i have to address all 1024 pixels in one sec and repeat the process .
MANJUNATH
MANJUNATH il 17 Ott 2012
Sir,
i have a sensor with 32 by 32 pixels , addressing each pixel gives me the voltage value of that pixel as an output, that obtained output has to be displayed in the form of an gray scale image(imshow with 32 rows and 32 col.). Addressing individual pixel should be so fast that within 1 sec all 1024 pixel has to be addressed and their output is displayed . This scan has to repeat after every second.
To address one single pixel i used bvdata=logical[0 0 0 0 0 0 0 ..] putvalue=(dio,bvdata).
but now i have make a loop so that each and every pixel is addressed and corresponding output is displayed .

Accedi per commentare.

Più risposte (1)

Sachin Ganjare
Sachin Ganjare il 17 Ott 2012
What exactly is your requirment, please elaborate.
  1 Commento
MANJUNATH
MANJUNATH il 17 Ott 2012
i want to create matrix with 32 rows and 32 columns , the elements will be data obtained from the analoginput to the DAQ
where each element corresponds to each pixel of a sensor

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by