Convert to three dimensional data

Hi guys,
I have this problem for some time which I dont know how to approach and solve. I am trying to create a three dimensional data from a two dimensional. I have data in the format:
C1 C2 C3 C4
1 2 3 10
4 6 9 20
5 4 1 10
...
and variables in C1 are 1st dimension, variables in C2 are 2nd dimension and those in C3 are 3rd dimension. C4 is the value created by three vectors in each dimension, such {1,2,3}=4. Appreciate any suggestion or thoughts.

2 个评论

Do you mean C1 , C2 and C3 are indices?
Not exactly sure what you're going for. Are you trying to plot this data in 3D? If so, try below, where your data should already be in a 2D array I called 'C'.
N = 10;
C = rand(N,4);
%get each variable separately
C1 = C(:,1);
C2 = C(:,2);
C3 = C(:,3);
C4 = C(:,4);
%plot data in 3D, with C4 value as the color
scatter3(C1,C2,C3,[],C4);
axis equal tight;
Or are you trying to get a 3D array from your 2D array? Unclear how you would like that to work. You might want to look at reshape(), which can reshape your array dimensions in to as many dimensions as you would like. Note that with an array, it must be an n-dimensional rectangle.

请先登录,再进行评论。

 采纳的回答

Stephen23
Stephen23 2016-3-22
编辑:Stephen23 2016-3-22
How to convert row, column, and page indices into an array:
>> M = [1,2,3,10;4,6,9,20;5,4,1,10]
M =
1 2 3 10
4 6 9 20
5 4 1 10
>> out = zeros(max(M(:,1:3)));
>> out(sub2ind(size(out),M(:,1),M(:,2),M(:,3))) = M(:,4);
And checking the locations of where those data have been allocated to:
>> X = find(out); % find non-zero elements
>> out(X) % show their values
ans =
10
10
20
>> [R,C,P] = ind2sub(size(out),X) % and their indices
R =
5
1
4
C =
4
2
6
P =
1
3
9

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by