IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Scilab Discussion :

Visualiser matrice Scilab avec Excel


Sujet :

Scilab

  1. #1
    Nouveau membre du Club
    Inscrit en
    Juin 2009
    Messages
    40
    Détails du profil
    Informations forums :
    Inscription : Juin 2009
    Messages : 40
    Points : 27
    Points
    27
    Par défaut Visualiser matrice Scilab avec Excel
    Bonjour
    Scilab est pratique pour faire des algos sophistiqués en mathematiques
    Par contre Excel est tres pratique pour visualiser une matrice.
    voici donc le code ci dessous pour ce faire.
    ici le code est fait pour visualiser une matrice de polynomes
    mais il suffit de remplacer pol2str(PolyM) par PolyM pour visualiser une matrice simple.
    Code Scilab:

    pour la creation des dossier:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    cd home ;
    cd documents ;
    // create dir Scilab if it does not exist
    sc=createdir("Scilab") ;
    cd Scilab ;
    sc=createdir("TestMyCode") ;
    cd TestMyCode ;
    exec("MyFunctions.sci");// les fonctions sont chez moi dans un fichier .sci et le code principale dans un .sce
    sc=createdir("Work");
    WorkPath = pwd() ;
    WorkPath = WorkPath  + "\Work" ;
    cd Work ;

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    // this function makes a CSV conversion of a  Polynomial matrix
    // in the file WorkPath + '\'+ texto +' '+ string(p) + 'pow' + string(n)  + '.csv'
    function CsvMatrix(PolyM,texto,p,n,WorkPath)
     x=poly(0,'x');
     csvWrite(pol2str(PolyM), WorkPath + '\'+ texto +'_'+ string(p) + 'E' + string(n)  + '.csv' , CsvDelimiter);
    endfunction
     
    global CsvDelimiter
    cd Work ;
    CsvDelimiter=','// for french Excel CSV delimiter
    //CsvDelimiter=';'// for english Excel CSV delimiter
    //  launch Excel
    dos('start excel.exe /r ImportCsvFiles.xls');
    voici ci dessous le code VBA utilisé dans le fichier ImportCsvFiles.xls
    autoriser les macros, et dans reference il faut ajouter :
    Microsoft Office Object Library et Microsoft Excel Object Library
    je joint le fichier ImportCsvFiles.xls
    il faut qu'il soit dans le meme dossier que les CSV.
    j'ai oublié de preciser que cela transforme les csv en xls ce qui est pratique pour mettre des couleurs
    pour agrementer la lecture. il faut bien sur aussi adapter le code qui est juste derriere les 2 lignes de code ci dessous

    Code VBA : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    NameStr = "PrimitivesPoly"
    If InStr(1, ws.Name, NameStr, vbTextCompare) = 0 Then
     'here it's a mult or add file

    qui fait un traitement couleur different selon que le nom de fichier CSV comporte la chaine PrimitivesPoly
    ou non.


    Code VBA : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
     
    Option Explicit
    Sub mainExe()
    Call ImportCSVs
    Call ListWorkbooks
    End Sub
    Sub ImportCSVs()
    'Author:    Jerry Beaucaire
    'Date:      8/16/2010
    'Summary:   Import all CSV files from a folder into separate sheets
    '           named for the CSV filenames
     
    'Update:    2/8/2013   Macro replaces existing sheets if they already exist in master workbook
     
    Dim fPath   As String
    Dim fCSV    As String
    Dim wbCSV   As Workbook
    Dim wbMST   As Workbook
     
    Set wbMST = ThisWorkbook
    fPath = ThisWorkbook.Path & "\" 'path to CSV files, include the final \
    Debug.Print "fPath:" & fPath
    Application.ScreenUpdating = False  'speed up macro
    Application.DisplayAlerts = False   'no error messages, take default answers
    fCSV = Dir(fPath & "*.csv")         'start the CSV file listing
     
        On Error Resume Next
        Do While Len(fCSV) > 0
            Set wbCSV = Workbooks.Open(fPath & fCSV)                    'open a CSV file
            wbCSV.Sheets(ActiveSheet.Name).Delete                       'delete sheet if it exists
            'wbMST.ActiveSheet.TextFileSemicolonDelimiter = True
            ActiveSheet.Move After:=wbMST.Sheets(wbMST.Sheets.Count)    'move new sheet into Mstr
            'wbMST.ActiveSheet.TextFileSemicolonDelimiter = True
            Columns.AutoFit             'clean up display
            'ActiveSheet.TextFileSemicolonDelimiter = True
            fCSV = Dir                  'ready next CSV
        Loop
     
    Application.ScreenUpdating = True
    Set wbCSV = Nothing
    End Sub
     
    Sub ListWorkbooks()
     
    Dim wb As Workbook
    Dim ws As Worksheet
     
    Dim wbW As Workbook
    Dim wsW As Worksheet
     
    Dim fPath   As String
     
    Dim NameStr   As String
     
    Dim i As Single, j As Single
    Dim k As Long
    Dim lCol As Long
    Dim NbIrreduciblePoly As Long
    Dim NbPolyTested As Long
     
    Set wbW = ThisWorkbook
    Set wsW = ThisWorkbook.Worksheets("Work")
    wsW.Cells.Select
    Selection.ClearContents
    fPath = ThisWorkbook.Path & "\"
     
    For j = 1 To Workbooks.Count
     
        wsW.Cells(j, 1) = Workbooks(j).Name
        Set wb = Workbooks(j)
        For i = 1 To Workbooks(j).Sheets.Count
        Set ws = wb.Sheets(i)
         'i stay at 1 value (CSV files) only one sheet possible!
            wsW.Cells(j, i + 1) = ws.Name
            If j > 1 Then
            NameStr = "PrimitivesPoly"
                If InStr(1, ws.Name, NameStr, vbTextCompare) = 0 Then
                 'here it's a mult or add file
                        ws.Cells(1, 1).EntireRow.Interior.ColorIndex = 7
                        ws.Cells(1, 1).EntireColumn.Interior.ColorIndex = 7
    '                   ws.Cells(1, 1).EntireRow.HorizontalAlignment = xlCenter
    '                   ws.Cells(1, 1).EntireColumn.HorizontalAlignment = xlCenter
    '                   ws.Cells(1, 1).EntireRow.VerticalAlignment = xlCenter
    '                   ws.Cells(1, 1).EntireColumn.VerticalAlignment = xlCenter
                        ws.Cells(1, 1).EntireRow.RowHeight = 25
                        ws.Cells.Columns.VerticalAlignment = xlCenter
                        ws.Cells.Columns.HorizontalAlignment = xlCenter
     
                Else
                'here it's a Primitives Polynomial files
     
                        ws.Cells(1, 1).EntireRow.Interior.ColorIndex = 7
                        ws.Cells(2, 1).Interior.ColorIndex = 7
    '                   ws.Cells(1, 1).EntireRow.HorizontalAlignment = xlCenter
    '                   ws.Cells(1, 1).EntireColumn.HorizontalAlignment = xlCenter
    '                   ws.Cells(1, 1).EntireRow.VerticalAlignment = xlCenter
    '                   ws.Cells(1, 1).EntireColumn.VerticalAlignment = xlCenter
                        ws.Cells(1, 1).EntireRow.RowHeight = 25
                        ws.Cells.Columns.VerticalAlignment = xlCenter
                        ws.Cells.Columns.HorizontalAlignment = xlCenter
                        'Find the last non-blank cell in row 1
                        lCol = ws.Cells(1, Columns.Count).End(xlToLeft).Column
                        Debug.Print "end of column:" & lCol
                        NbIrreduciblePoly = 0
                        NbPolyTested = 0
                        For k = 1 To lCol
                            If ws.Cells(2, k) = 1 Then
                                ws.Cells(2, k).Interior.Color = RGB(100, 250, 100)
                                NbIrreduciblePoly = NbIrreduciblePoly + 1
                            End If
                            NbPolyTested = NbPolyTested + 1
                        Next k
                        ws.Cells(3, 1) = "NbIrreduciblePoly:"
                        ws.Cells(3, 2) = NbIrreduciblePoly
                        ws.Cells(4, 1) = "NbPolyTested:"
                        ws.Cells(4, 2) = NbPolyTested
                        'Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = NameStr & "Classified"
                End If
                ' save file in xls format xlExcel9795   43 Excel9795
                'workbook.SaveAs(FileName, FileFormat)
                wb.SaveAs Filename:=fPath & wb.Sheets(i).Name, FileFormat:=xlWorkbookNormal
            End If
        Set ws = Nothing
        Next i
       Set wb = Nothing
     
    Next j
     
     
     
    End Sub
    Fichiers attachés Fichiers attachés

  2. #2
    Nouveau membre du Club
    Inscrit en
    Juin 2009
    Messages
    40
    Détails du profil
    Informations forums :
    Inscription : Juin 2009
    Messages : 40
    Points : 27
    Points
    27
    Par défaut nouvelle version de ImportCsvFiles.xls
    Bonjour
    j'ai amélioré un peu le fichier ImportCsvFiles.xls
    c'est maintenant la version 3 ImportCsvFiles3.xls.
    il n’était pas normale que le fichier ImportCsvFiles3.xls de traitement des fichiers se trouvait
    dans le dossier Work, je l'ai remonté d'un cran.
    de plus j'ai rajouté un bouton merge qui rassemble tous les xls créés, dans différentes pages,
    toutes dans le fichier ImportCsvFiles3.xls. et aussi un bouton delete qui efface toutes les feuilles excepté la page Work
    du fichier ImportCsvFiles3.xls.
    je joint un fichier compressé avec un dossier TestImportCsvInXls
    qui comporte ImportCsvFiles3.xls et en dessous le dossier work avec des fichiers de matrices de polynômes Scilab en CSV pour tester.

    les matrices Scilab sous forme CSV ne sont pas obligatoirement des matrices de polynômes ça peut être autre chose.
    il se trouve que dans mon cas ce sont des matrices de polynomes.

    si quelqu'un a des améliorations a proposer je suis preneur.
    Fichiers attachés Fichiers attachés

  3. #3
    Nouveau membre du Club
    Inscrit en
    Juin 2009
    Messages
    40
    Détails du profil
    Informations forums :
    Inscription : Juin 2009
    Messages : 40
    Points : 27
    Points
    27
    Par défaut
    il a fallu modifier la procedure ImportThisOne afin de n'ouvrir le xls créé a partir d'un csv pour le merger avec les autres dans le fichier ImportCsvFiles4.xls
    qu'a la condition qu'il ne soit pas deja ouvert.

    le petit bout de code ajouté:
    Code VBA : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
      Set oBook = Workbooks(sFileName)
       If oBook Is Nothing Then
        Set oBook = Workbooks.Open(sFileName)
       End If

    ci dessous dans cette procedure déjà existante

    Code VBA : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    Sub ImportThisOne(sFileName As String)
    On Error Resume Next
       Dim oBook As Workbook
       Set oBook = Workbooks(sFileName)
       If oBook Is Nothing Then
        Set oBook = Workbooks.Open(sFileName)
       End If
       'Now do your processing on the newly imported sheet
       On Error Resume Next
       'Copy new sheet into this workbook
       oBook.Worksheets(1).Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
       'close text file, do not save changes
       'oBook.Close False
       'Set oBook = Nothing
    End Sub

Discussions similaires

  1. Construire une matrice avec excel 2007
    Par Ksawery dans le forum Excel
    Réponses: 2
    Dernier message: 02/03/2009, 13h51
  2. macro imprimer un matrice word avec champ excel
    Par stephlinternaute dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 08/08/2007, 19h00
  3. [MFC] [CRecordset] Problème avec Excel
    Par Yellowmat dans le forum MFC
    Réponses: 4
    Dernier message: 20/07/2005, 15h24
  4. Analyse avec Excel
    Par Ric500 dans le forum Access
    Réponses: 6
    Dernier message: 15/02/2005, 15h12
  5. [C#] [EXCEL] Travailler avec EXCEL sans ouvrir le logiciel
    Par Fabsou dans le forum Windows Forms
    Réponses: 3
    Dernier message: 16/07/2004, 10h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo