Functions acting on matrix entries

2 ビュー (過去 30 日間)
Joe
Joe 2014 年 1 月 20 日
コメント済み: Joe 2014 年 1 月 20 日
For instance lets say I want to create a matrix A(i,1) where A(i,1)=dec2bin(B(i,1),n)-'0', I'm not able to do this because I presume I'm using an entry B(i,1) which is an entry of a matrix defined before. How can I create such a matrix which relies on entries of other matrices? This is something also I've faced problems on other occasions, I put my data in matrix form however I can't have my functions to act on the elements individually to produce a matrix, I've tried to use the ., e.g. square the elements of the matrix X I would do X.^2 but this isnt really helping me.
Thanks
Joe

回答 (1 件)

John D'Errico
John D'Errico 2014 年 1 月 20 日
No. You presume wrong. The problem is NOT because you are using B(i,1). The problem is because you are trying to stuff the result into a scalar, i.e., A((i,1).
Note that dec2bin is able to act on an entire vector of elements at once. Learn to use these capabilities, and your code will improve greatly.
  1 件のコメント
Joe
Joe 2014 年 1 月 20 日
after thinking about what i wrote, yes you are correct, trying to form a binary to be a scalar is definitely wrong, so is there a way to store binary like a binary matrix?

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by