convert logical values to numeric values

82 ビュー (過去 30 日間)
William Gray
William Gray 2021 年 3 月 2 日
コメント済み: William Gray 2021 年 3 月 2 日
Hi Everyone,
Really simple question but I'm struggling converting a logical array from an ischange function to a double matix. I've written the following code just to show the issue I am having. How do I convert the b to a double matrix?
Thanks!
a=[1 1 5 1 1]
b = ischange(a)
c = cell2mat(b)

採用された回答

Jan
Jan 2021 年 3 月 2 日
編集済み: Jan 2021 年 3 月 2 日
a = [1 1 5 1 1]
b = ischange(a)
c = double(b)
% Alternative:
d = b + 0 % Addition with DOUBLE converts to double
cell2mat needs a cell array as input, but here are no cells.
  1 件のコメント
William Gray
William Gray 2021 年 3 月 2 日
That's great, thanks!

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2021 年 3 月 2 日
What do you want the double array to represent?
  • Just 0 and 1 instead on false and true? Use Jan's approach.
  • 0 where there isn't a change point, the value of the original signal where there is? Use .* to multiply the original signal and the logical vector.
  • The indices where the change points occur in the original signal? You can use find for this, but if you're planning to use this for indexing (to get just the change point value) you can use the logical array returned by ischange to perform logical indexing.
  • Something else, in which case please explain what you want to do in more detail.
  1 件のコメント
William Gray
William Gray 2021 年 3 月 2 日
just a 0 for no change, a 1 where there is a change point so Jan's approach worked, but thank you for this, also very useful!

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

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by