Decimal to Canonical SIgned Digit (CSD) conversion and CSD matrix multilplication with decimal matrix

9 次查看(过去 30 天)
I got a code which takes an input value and gives the output in Canonical Signed Digit (CSD) form. I took the code from this link: http://www.mathworks.com/matlabcentral/fileexchange/9730-canonical-signed-digits/content/csdigit.m. But i am facing problem when i want to convert all the elements of a matrix in to CSD form. I used following codes in MATLAB:
X = [-7.1989 0.9546; 2.6903 -5.0001];
[rows cols] = size(X);
W = zeros(rows, cols);
for i = 1:rows
for j = 1: cols
W(i, j) = csdigit(X(i, j), 4, 10)
end
end
W %CSD matrix
But it's showing an error:
??? Subscripted assignment dimension mismatch.
Error in ==> csdmatrix at 6 W(i, j) = csdigit(X(i, j), 4, 10)
How can i remove the error?
Next,i want to perform matrix multiplication in Canonical Signed Digit (CSD) form where A = W*P. Here W is the CSD matrix and P = [0.2597; -5.3109]. Here, each elemant value of P is in fractional decimal form and column size is variable. After performing multiplication of W*P, the resultant matrix A is in decimal form. Please help me in MATLAB coding to perform this multiplication.

回答(1 个)

Walter Roberson
Walter Roberson 2011-12-6
csdigit(X(i, j), 4, 10) probably returns a vector of values (possibly a row vector of characters, also known as a string). You cannot store a vector of numeric values or a multi-character string in a single numeric array location. You will either need to go up one dimension or else switch to a cell array.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by