フィルターのクリア

Is it possible to compare individual values of two vectors without a for loop?

2 ビュー (過去 30 日間)
Thomas Sherk
Thomas Sherk 2019 年 2 月 5 日
回答済み: Fangjun Jiang 2019 年 2 月 5 日
a & b are string vectors of 1 x 2,000,000
c is an empty integer vector of 1 x 2,000,000
Using for loops, my code is thus:
for i = 1:2000000
if a(1,i) == b(1,i)
c(1,i) = 1;
else
c(1,i) = 0;
end
end
This is a simple example of what I'm trying to accomplish, but I'm looking for a faster way to do this and I don't know how to 'vectorize' comparisons.

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2019 年 2 月 5 日
a="abc";
b="Abc";
c=char(a)==char(b)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by