Group Abstract Group Abstract

Message Boards Message Boards

0
|
7.1K Views
|
5 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Extract part of a Table with the Wolfram Language?

Hi, I am not an expert with Mathematica, i'm just approaching to this software. I should extract elements from a Table called 'sort', if the first term of the element is equal to a certain value. How can I do this? I have also developed a code, but I don't know how can I implement in Mathematica:

table=Table[{}]
cont=0
cont2=0
For i=1 to npoint
 If sort[[i]][[1]]=sort[[i+1]][[1]] Then
      cont=cont+1
      table=Table[{pippo,sort[[i+1]][[1]]}]
 Elseif cont>0
    cont2=cont2+1
    table(cont2)=table
    Print table(cont2)
    cont=0
 End if
Next i

There is someone who can help me?

5 Replies

Thanks for the answer Gustavo, I solved with this:

ascisse = Table[sort[[i]][[1]], {i, 1, npunti}];

ascisse2 = DeleteDuplicates[ascisse];

nscisse2 = Length[ascisse2];

vettoreord = Table[{}];

For[i = 1, i < nscisse2 + 1, i++,

riga = Cases[sort, {ascisse2[[i]], , }];

ordinateriga = Table[riga[[i]][[2]], {i, 1, Length[riga]}];

psi = Table[riga[[i]][[3]], {i, 1, Length[riga]}];

mediaord = Mean[ordinateriga];

vettoreord = Append[vettoreord, mediaord]];

The problem was that some abscissa were assosiated to more ordinates. Really thank you for yours advice.

Posted 10 years ago

Francesco, there is an important difference between what you ask and the code you provide. If you just want to select the rows that meed a criteria, using Cases, Select or even Query is the way to go. But you code suggests that to test a line, you need information about the next line. In this case you need to look into using Partition first.

Avoid using the traditional For and While as they almost always lead to solutions more complicated than needed.

POSTED BY: Gustavo Delfino

Thanks for your answer. This procedure works, but my problem is to automate the calculation in a loop. In fact I need more or less 1300 extraction for all the different values ??that assumes the first component of each element of the table. These values also include numbers with long decimal points.

Posted 10 years ago
POSTED BY: Bill Simpson
Posted 10 years ago
POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard