Finding diag of two cells
古いコメントを表示
Hello,
I have two cells(a and b) each with size 1x4 and each of them contains 2x1 matrix in each of its columns. I would like to find diag([a b]) to get a 2x2 matrix but it seems that diag() is not defined for cell. Can anybody tell me what I should do?
1 件のコメント
Nathan Greco
2011 年 7 月 25 日
What 2x2 matrix are you looking for? diag([a b]) would provide a 2x1 matrix. Are you looking for [diag(a) diag(b)]? When asking questions, please provide sample inputs with an example of the expected result.
採用された回答
その他の回答 (1 件)
Nathan Greco
2011 年 7 月 25 日
Does this work for you?
diag(cell2mat([a b]))
Note that the solution is the same as:
diag([a{1} a{2}])
To get the diag of both a and b, do this:
[diag(cell2mat(a)) diag(cell2mat(b))]
-Nathan
11 件のコメント
Bahareh
2011 年 7 月 25 日
Nathan Greco
2011 年 7 月 25 日
Does my answer work for you? If not, what are you looking to retrieve?
Bahareh
2011 年 7 月 25 日
Nathan Greco
2011 年 7 月 25 日
Your question asked for a 2x1 matrix. Please explain what you are looking for. Provide me example values for "a" and "b", and what you expect your result from "diag" to be. I wish I could read your mind.
Bahareh
2011 年 7 月 25 日
Nathan Greco
2011 年 7 月 25 日
One way: type a{:} and show me what it says. Another way: double click on "a" in your "Workspace" window.
Bahareh
2011 年 7 月 26 日
Nathan Greco
2011 年 7 月 26 日
What is b supposed to be? What is the final solution to this problem supposed to be? You are leaving out important information. If I gave you a = {[1;2] [3;4] [5;6] [7;8]}; and b = {[.1;.2] [.3;.4] [.5;.6] [.7;.8]}; What would the result of your diag([a b]) be?
Bahareh
2011 年 7 月 26 日
Nathan Greco
2011 年 7 月 26 日
You are very unhelpful and wasted my time.
Jan
2011 年 7 月 26 日
@Nathan: But without doubt Bahareh is very polite and thanked your repeatedly. It was obviously not his intentention to waste your time.
カテゴリ
ヘルプ センター および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!