Array multiplication

51 views
Skip to first unread message

Ganesh

unread,
May 19, 2011, 7:09:34 AM5/19/11
to freemat-devel
Hi,

I am new to freemat. I am getting below mentioned error when I try to
multiply each elements of array by a number.

--> a = {1,2;3,4}

a =

[1] [2]
[3] [4]

--> a = a .* 2
Error: Cannot perform type conversions with this type

Can anyone help me on this? I am using freematv4.0 in windows vista.

-Thanks
Ganesh

Timothy Cyders

unread,
May 19, 2011, 7:23:57 AM5/19/11
to freema...@googlegroups.com
Ganesh,

the type of brackets you use is very important. When you use {, it creates a cell array, which is slightly different from a matrix. A cell array allows you to store different types of information in the same cell (for example, I could say a = { [1:10], 'hello',14}, and it would save it as  such - a double array, a string and an int. Because of this, plain matrix operations don't generally work with cells the same way they do with matrices. If you use square brackets, however, you create a plain Jane matrix (which you can do all sorts of mathematical operations with), like so:


a = [1,2;3,4]

a =
 1 2
 3 4

--> a = a.*2

a =
  4  8
 12 16

Hope this helps!

TJ


--
You received this message because you are subscribed to the Google Groups "freemat-devel" group.
To post to this group, send email to freema...@googlegroups.com.
To unsubscribe from this group, send email to freemat-deve...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/freemat-devel?hl=en.


Reply all
Reply to author
Forward
0 new messages