re-formatting a matrix

6 ビュー (過去 30 日間)
Richard
Richard 2012 年 10 月 26 日
This is a simplistic example of a problem I am facing:
depth = [0:1:20]';
data = rand(1,length(depth))';
d = [depth,data];
d = [d;d;d];
Consider the matrix 'd'. Here we have depth in the first column followed by temperature measurements recorded at that depth in column 2 (in this example we have 3 days of data). How could I alter this matrix so that each column represents a specific depth and each row represents time. So, finally I should have 3 rows with 21 columns (hence I do not need the column of depths).

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 10 月 26 日
dout = reshape(d(:,2),numel(depth),[]).';

その他の回答 (1 件)

Daniel Shub
Daniel Shub 2012 年 10 月 26 日
First lets create some dummy data. I am intentionally creating it in a non-optimal manner
depth = [0:1:20]';
data1 = rand(length(depth), 1);
data2 = rand(length(depth), 1);
data3 = rand(length(depth), 1);
You can then do
d = [depth, data1, data2, data3]
A better way to generate the data would be
data(:, 1) = rand(length(depth), 1);
data(:, 2) = rand(length(depth), 1);
data(:, 3) = rand(length(depth), 1);
and then
d = [depth, data]
You could of course do
data = rand(length(depth), 3);
but this probably doesn't work with your work flow of how you have the actual data saved.

カテゴリ

Help Center および File ExchangeR Language についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by