フィルターのクリア

how to Add two arrays representing integers base B--Test+function?

1 回表示 (過去 30 日間)
Ekram Adam
Ekram Adam 2017 年 9 月 4 日
回答済み: Kris Fedorenko 2017 年 9 月 7 日
Pseudo-Code: The variables are X, Y, Z, C which are all flipped arrays of proper size. This means that x₀ should be denoted X(1). 1.Add the two arrays X and Y and call it XpY element by element 2.for element i if XpY(i)> B-1, then XpY(i)=XpY(i)-B. Else do nothing. 3.If C=0 (every element is zero) then Z=XpY and I am done. Else X=XpY and Y=C, and repeat. X = [0, 6,6,6,6] ; Y = [0, 6,6,6,1]; % represents 6661 in base 7 B=7 ; [Z] = AddXYBaseB(X, Y, B) AddXYBaseB([6,6],[6,6],7)

回答 (1 件)

Kris Fedorenko
Kris Fedorenko 2017 年 9 月 7 日
Hi Ekram!
Element-wise addition of two vectors (of the same length) can be achieved simply by using the " + " operator in MATLAB. For example:
>> A = [ 1, 2, 3];
>> B = [ 1, 0, 5];
>> C = A+B
C =
2 2 8
For editing the XpY vector based on its values, consider examples in the following link: https://www.mathworks.com/help/matlab/matlab_prog/find-array-elements-that-meet-a-condition.html#bt_xjh4
For checking whether the vector contains all zeros, you can look into the " nnz " function.
You might also find MATLAB's conditional statements (if statements) and loops useful.
Hope this helps!
Kris

カテゴリ

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

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by