Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
trouble create 3d array from data

Subject: trouble create 3d array from data

From: skl80

Date: 23 Feb, 2009 15:51:29

Message: 1 of 5

Hi everybody, let me explain the problem...

I've got some x,y,z,v data calculated on a regular grid (in order to
use interp3)
Assume that this data are as the following
X = [0 1];
Y = [1:10];
Z = [5 6];

X,Y,Z describe the coordinates in the (x,y,z) space in which we have
computed the value of the fourth variable V.

So we can obtain the grid for interp3 with [XI, YI, ZI] = ndgrid
(X,Y,Z).

Now the problem is to build the 3D array V needed for interp3
function, because I want to use the function in the form interp3
(X,Y,Z,V,XI,YI,ZI).

In fact the values of V are given as following:

x(1) y(1) z(1) V_value_1;
x(1) y(2) z(1) V_value_2;
...
x(1) y(1) z(2) V_value_k;
x(1) y(2) z(2) V_value_k1;
...
x(2) y(1) z(1) V_value_w;
x(2) y(2) z(1) V_value_w1;
...
x(2) y(1) z(2) V_value_ww;
x(2) y(2) z(2) V_value_ww2;
...


How can I quick build the 3D array of V values ?

thanks for responses,

LT

Subject: trouble create 3d array from data

From: kinwin Wong

Date: 24 Apr, 2009 19:29:02

Message: 2 of 5

I've got the same problem. Anybody have any ideas?

Subject: trouble create 3d array from data

From: kinwin Wong

Date: 24 Apr, 2009 19:30:03

Message: 3 of 5

I've got the same problem. Anybody have any ideas?

Subject: trouble create 3d array from data

From: Gustavo Morales

Date: 25 Apr, 2009 05:35:03

Message: 4 of 5

skl80:

Hi...
Here's the code I think answer your question:

function [f] = arrayval(X,Y,Z)
% I'll suposse that X,Y,Z were obtained by meshgrid and have the same
% dimensions
[ny nx nz] = size(X); %ny: # of y(i) values
N = nx*ny*nz; % total # of (x,y,z) points
f = zeros(nx,ny,nz); %preallocating array f
for i = 1:N
    prompt = ['The value of f(',num2str(X(i)),',',num2str(Y(i)),',',num2str(Z(i)),') = '];
    f(i) = input(prompt);
end
f = reshape(f,[nx ny nz]); % positions of f elements must be congruent with X, Y and % Z positions

Adapt the code to your needs and Enjoy......!

Subject: trouble create 3d array from data

From: derya.akkaynak@gmail.com

Date: 4 Jun, 2009 22:19:17

Message: 5 of 5

Hey Gustavo,

I can't tell you how much your answer to skl80's question helped me!
Thank you so much!

da

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us