Group Abstract Group Abstract

Message Boards Message Boards

0
|
5.6K Views
|
1 Reply
|
1 Total Like
View groups...
Share
Share this post:

How can I display a Table from a For Loop result?

Posted 10 years ago

Hi. I´m working with a file that contains two columns of data (s1 and s2). I´m doing calculations between them and in a part of the program I use a For Loop. The result of this Loop will be a set of data of three vectors because the operations are between two columns and as the for loop indicates, values from 0 to 2. The result is displayed above and each vector would be a column (so the result is correct) but they aren´t separate with a coma. My question is: how can I do this procedure so that the result is displayed as a table?

For[x = 0, x < 3, x++, y = (s1*x) +  (s2+x); Print[y]]

{0,0,0,0,0,0,0}

{3,0,4,9,15,16,22}

{4,0,8,18,30,32,44}
POSTED BY: URIEL NOGAL
Posted 10 years ago

I don't fully understand your question, but I think it's better for you to Map rather than use a For loop. For example:

# * (s1 + s2) & /@ Range[0, 3]

Later, if you're wanting to show it in a table or grid, you can use something like TableForm or Grid.

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