Message Boards Message Boards

[?] Import a number from Excel?

Posted 5 years ago

Hi,

I have currently loaded a complex number from an excel file and when I display it, it seems to be fine e.g. 1.3 + 4.2I. However, when I try doing operations on it, it doesn't seem to work.

What I mean is say I have an excel cell with the number 1.3+4.2I and Import this and assign this to variable x. If I print x, it says 1.3+4.2I. But if I print x + 1, it will says 1.3+4.2I+1 rather than 2.3+4.2I.

I think mathematica might be importing the excel cell as text, but I am not sure.

2 Replies
Posted 5 years ago

It probably is a String.

s = "1.3+4.2I";
s + 1
(* 1 + 1.3+4.2I *)

Head@s
(* String *)

c = ToExpression@s
Head@c
(* Complex *)

c + 1
(* 2.3 + 4.2 I *)
POSTED BY: Rohit Namjoshi

Yep thi solved it perfectly, thank you

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract