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 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 3 月 22 日
Do you mean C1 , C2 and C3 are indices?
Charles Dunn
Charles Dunn 2016 年 3 月 22 日
編集済み: Charles Dunn 2016 年 3 月 22 日
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 日

1 投票

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

1 件のコメント

art
art 2016 年 3 月 22 日
Stephen, thanks very much. It is truly helpful.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で MATLAB についてさらに検索

質問済み:

art
2016 年 3 月 22 日

コメント済み:

art
2016 年 3 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by