one thing i need to know

1 回表示 (過去 30 日間)
ar fa
ar fa 2015 年 4 月 2 日
コメント済み: Star Strider 2015 年 4 月 3 日
hello I am c# programmer. after coding using matlab, I was faced with a problem. I can't convert below c# codes to matlab:
public double[][] Transpose(double[][] M)
{
double[][] R = new double[M[0].Length][];
for (int c = 0; c < M[0].Length; c++)
R[c] = new double[M.Length];
for (int i = 0; i < M.Length; i++)
{
for (int j = 0; j < M[0].Length; j++)
{
R[j][i] = M[i][j];
}
}
return R;
}
Please Help me to convert this code to matlab code and not recommend to use matlab function. Thanks

採用された回答

ar fa
ar fa 2015 年 4 月 3 日
編集済み: James Tursa 2015 年 4 月 3 日
I find solution for creating dynamic array in matlab:
How to Create it:
x = {zeros(1,30);zeros(1,20);zeros(1,10)};
x{4} = x;
How to Access it:
Write:
x{4}{1}(25) = 5;
Read:
x{4}{1}
Good luck
  2 件のコメント
James Tursa
James Tursa 2015 年 4 月 3 日
編集済み: James Tursa 2015 年 4 月 3 日
Wow ... so all this time you simply wanted the dynamic memory allocation of array of pointers to arrays capability in C# translated into cell array of cell arrays in MATLAB. I never would have guessed ...
Star Strider
Star Strider 2015 年 4 月 3 日
... and that’s the one thing ‘ar fa’ needs to know.
Now, a universal polymath!

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

その他の回答 (2 件)

James Tursa
James Tursa 2015 年 4 月 2 日
編集済み: James Tursa 2015 年 4 月 2 日
R = M'
Or if you want to strictly transpose for complex arguments as well,
R = M.'
  3 件のコメント
James Tursa
James Tursa 2015 年 4 月 3 日
I have no idea what you are getting at. What does "R variable in C# code and simple access to any elements" mean? What does "Help me to create dynamic array" mean? You originally asked to convert the above C# code to MATLAB. I did that. Your original code just transposes a matrix. It uses a rather convoluted way to do this simply to preserve the [][] indexing syntax at the expense of not having all the data in the matrix contiguous, which is a bad choice IMO.
So what, exactly, are you after here? If you are not trying to convert the above code to MATLAB, then what do you want? Are you trying to connect some C# code with MATLAB (i.e., pass data between C# and MATLAB)?
Please be explicit because right now I have no idea what you really want.
Stephen23
Stephen23 2015 年 4 月 3 日
The second, non-conjugate transpose is the correct answer.

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


Andrew Newell
Andrew Newell 2015 年 4 月 2 日
For your specific problem, some useful pages are Matrix Indexing in MATLAB, Loop Control Statements and Create Functions in Files. But you seem to be starting from zero knowledge of MATLAB, so you really should start with a tutorial. It wouldn't do you much good if we simply converted your function to MATLAB because you wouldn't know what to do with it.

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by