Info

This question is closed. Reopen it to edit or answer.

How can I convert some cell arrays into numbers that can by multiplied by a number?

1 view (last 30 days)
I have a function that generates a matrix composed of cells (some of them numbers other text). Although this function was initially generated for my GUI, I need to use these values in another function, for that I've used:
setappdata(0,'MatrixData_n',MatrixData_n);
MatrixData_n = getappdata(0,'MatrixData_n')
However now I need to multiply some of the cells of this matrix by a number and I don't know how to convert them in the correct format.
Thanks,

Answers (1)

Image Analyst
Image Analyst on 13 Nov 2015
First extract the numerical matrix from the cell that contains a numerical matrix that you want to multiply by some number:
theMatrix = MatrixData_n{index}; % Braces mean "contents of"
where index is the number of the cell from which you want to extract the numerical array. theMatrix is now just the bare numerical matrix - it's not wrapped in a cell. Now multiply the matrix by some number:
scaledMatrix = theMatrix * someNumber;
You can get a good feel for these kinds of operations if you read the FAQ: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
  4 Comments
Guillaume
Guillaume on 16 Nov 2015
One possibility:
[m, n] = max(size(A), size(B))
if any([m n] > size(A))
A(m, n) = 0;
end
if any([m n] > size(B))
B(m, n) = 0;
end

Community Treasure Hunt

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

Start Hunting!