converting 3 arrays into matrix

32 Ansichten (letzte 30 Tage)
Ahmed Abdulla
Ahmed Abdulla am 8 Jul. 2019
Beantwortet: Steven Lord am 10 Jul. 2019
i have 3 different arrays x,y and z and i would like to create one matrix M where the M(i,j)=z(i) and i and j in M are the corresponding x and y values.
Note that x and y are not whole numbers
  1 Kommentar
Jon
Jon am 8 Jul. 2019
I'm sorry, but I am having difficulty understanding your verbal description of your problem. Please provide a simple example with arrays x,y,and z and the matrix M that you would like to produce.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Steven Lord
Steven Lord am 10 Jul. 2019
You can't have an array in MATLAB whose element indices are non-integer values. If M is a matrix M(3.5, pi) will error (for example.)
What are you planning to do with this "matrix" M? You may need/want to create an object that will allow you to interpolate your data, like a scatteredInterpolant or griddedInterpolant.
If you don't want to perform interpolation but want to be able to map non-integer values to a value you could create a matrix like Adam Danz suggested and use ismember or ismembertol with the 'rows' flag when you need to "index" into that matrix with the non-integer values.

Weitere Antworten (1)

Adam Danz
Adam Danz am 9 Jul. 2019
Bearbeitet: Adam Danz am 10 Jul. 2019
It sounds like you want to horizontally concatenate three column vectors of equal length to form a matrix. If this doesn't demonstrate your question and its solution, please provide an example of the inputs and expected outputs.
x = randi(100,12,1);
y = randi(50, 12,1);
z = randi(15, 12,1);
M = [x,y,z];

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by