Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Bücher:

Gewöhnliche Differentialgleichungen

Fachkräfte:
weitere Angebote

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

Wrinting inside a file

 

sebbastiannn
Forum-Newbie

Forum-Newbie


Beiträge: 6
Anmeldedatum: 06.07.22
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 06.07.2022, 10:59     Titel: Wrinting inside a file
  Antworten mit Zitat      
Hallo zusammen,

ich habe ein kleines Problem mit fopen, fprintf ... bei der Ausführung des Codes erhalte ich folgende Fehlermeldung:

Warning: Escaped character '\P' is not valid. See 'doc sprintf' for supported special characters.
> In CallLTSpice (line 29)

Ich bin ein totaler Matlab Noob und verstehe nicht wo ein \P vorkommt was nicht funktioniert...
Ich will nur das er den Text Brocken von "code" in das .net file speichert Crying or Very sad

Ich habe beim einfügen des Textes gesehen das ein Symbol nicht übernommen werden kann weswegen ich für euch noch das .m File angefügt habe.

Am Ende wird das genutzt um LTSpice anzusteuern und eine Simulation zu machen was die Daten wieder an Matlab zurück gibt und ich es in einer While Schleife laufen lassen kann, daher auch kein .txt sondern .net Smile

Ich bedanke mich jetzt schon bei den Masterbrains!
Beste Grüße,
Basti

Code:

clc
clear all

netlist = ['D:\Profile\a2679\Desktop\LTSpice\Test\Tandem_3T-series_1step.net']

code=['d:\\Profile\\a2679\\Desktop\\LTSpice\\Test\\Tandem_3T-series.asc\r\n'...
    'V1 N001 0 0\r\n'...
    'D1 N001 N002 {dio2}\r\n'...
    'I1 N002 N001 {I1}\r\n'...
    'I�l2 N003 N002 {I2}\r\n'...
    'D2 N002 N003 {dio1}\r\n'...
    'V2 N002 0 {V2}\r\n'...
    'R1 0 N003 0.0001\r\n'...
    '.model D D\r\n'...
    '.lib d:\Profile\a2679\Eigene Dateien\LTspiceXVII\lib\cmp\standard.dio\r\n'...
    '.model dio1 D(Is=1.61E-14 N=1)\r\n'...
    '.step param V2 0.5 0.74 0.01\r\n'...
    '.dc V1 1.7 2.1 0.01\r\n'...
    '.model dio2 D(Is=1.61E-14 N=1)\r\n'...
    '.step param Eg list 100 101 102\r\n'...
    '.param I1 table(Eg,100,0.010181,101,0.002396,102,0.00135,103,0.00148,104,0.004685,105,0.009347,106,0.004385,107,0.00293,108,0.004306,109,0.001085,110,0.002713,111,0.007115,112,0.01176,113,0.009205,114,0.012395,115,0.010637,116,0.007705,117,0.003889,118,0.004473,119,0.004458,120,0.007028,121,0.004424,122,0.004744,123,0.002317,124,0.001604,125,0.001408,126,0.003859,127,0.005497,128,0.009094,129,0.009142,130,0.007416,131,0.004846,132,0.00441,133,0.000897,134,0.002066,135,0.006125,136,0.009597,137,0.011969,138,0.013016,139,0.012656,140,0.01093,141,0.007997,142,0.004145,143,0.001133,144,0.004098,145,0.004698,146,0.009444,147,0.009854,148,0.008939,149,0.005758,150,0.003959,151,0.001223,152,0.002135,153,0.006237,154,0.009744,155,0.012185,156,0.013314,157,0.013014,158,0.011275,159,0.00828,160,0.004387,161,0.00166,162,0.002527,163,0.002312,164,0.012179,165,0.013252,166,0.01289,167,0.011157,168,0.008181,169,0.004366,170,0.002175,171,0.006249,172,0.009724,173,0.01213,174,0.013246,175,0.012925,176,0.011234,177,0.00831,178,0.004482,179,0.001671,180,0.004339,181,0.003284,182,0.003467,183,0.002864,184,0.002384,185,0.004548,186,0.002662,187,0.001317,188,0.004753,189,0.007418,190,0.009172,191,0.009445,192,0.009707,193,0.007909,194,0.002901,195,0.004758,196,0.002353,197,0.006536,198,0.010079,199,0.012509)\r\n'...
    '.param I2 table(Eg,100,0.007164,101,0.001488,102,0.000744,103,0.000878,104,0.003188,105,0.006669,106,0.002929,107,0.001904,108,0.002883,109,0.000592,110,0.001763,111,0.005051,112,0.008361,113,0.006486,114,0.008775,115,0.007555,116,0.005518,117,0.002833,118,0.00299,119,0.002953,120,0.004828,121,0.002926,122,0.003169,123,0.001443,124,0.000932,125,0.00089,126,0.002673,127,0.003806,128,0.006457,129,0.006455,130,0.005164,131,0.003269,132,0.003,133,0.000468,134,0.001526,135,0.004491,136,0.006925,137,0.008566,138,0.009284,139,0.009027,140,0.007825,141,0.005776,142,0.00305,143,0.000623,144,0.002859,145,0.003203,146,0.006757,147,0.007037,148,0.006364,149,0.003991,150,0.002686,151,0.000692,152,0.001598,153,0.004606,154,0.007067,155,0.008753,156,0.009515,157,0.00929,158,0.008073,159,0.00598,160,0.003233,161,0.001112,162,0.001629,163,0.00148,164,0.008762,165,0.00951,166,0.009254,167,0.008036,168,0.005941,169,0.003221,170,0.001577,171,0.004517,172,0.006934,173,0.008591,174,0.009356,175,0.00913,176,0.007957,177,0.005925,178,0.003241,179,0.001074,180,0.002983,181,0.002122,182,0.002255,183,0.001848,184,0.001524,185,0.00303,186,0.001692,187,0.000744,188,0.003387,189,0.005297,190,0.006544,191,0.006719,192,0.006926,193,0.00562,194,0.001889,195,0.003523,196,0.001767,197,0.004807,198,0.007278,199,0.008945)\r\n'...
    '.backanno\r\n'...
    '.end\r\n'];
   
fid = fopen(netlist, 'w+');
fprintf(fid,code);
fid = fclose(fid);
 


CallLTSpice.m
 Beschreibung:

Download
 Dateiname:  CallLTSpice.m
 Dateigröße:  3.85 KB
 Heruntergeladen:  35 mal
Private Nachricht senden Benutzer-Profile anzeigen


Harald
Forum-Meister

Forum-Meister


Beiträge: 24.044
Anmeldedatum: 26.03.09
Wohnort: Nähe München
Version: ab 2017b
     Beitrag Verfasst am: 06.07.2022, 11:51     Titel:
  Antworten mit Zitat      
Hallo,

du musst bei fprintf das Format angeben, z.B.
Code:
fprintf(fid, "%s", code);


Ich würde code als String Array erstellen, also mit " " statt ' '.

Vermutlich muss das \r\n in das Format statt in die Variable, also
Code:
fprintf(fid, "%s\r\n", code);


Grüße,
Harald
_________________

1.) Ask MATLAB Documentation
2.) Search gomatlab.de, google.de or MATLAB Answers
3.) Ask Technical Support of MathWorks
4.) Go mad, your problem is unsolvable ;)
Private Nachricht senden Benutzer-Profile anzeigen
 
sebbastiannn
Themenstarter

Forum-Newbie

Forum-Newbie


Beiträge: 6
Anmeldedatum: 06.07.22
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 06.07.2022, 12:45     Titel:
  Antworten mit Zitat      
Harald hat Folgendes geschrieben:
Hallo,

du musst bei fprintf das Format angeben, z.B.
Code:
fprintf(fid, "%s", code);


Ich würde code als String Array erstellen, also mit " " statt ' '.

Vermutlich muss das \r\n in das Format statt in die Variable, also
Code:
fprintf(fid, "%s\r\n", code);


Grüße,
Harald


Perfekt! ich danke:))) Cool
Ich bekomme endlich mein Richtiges .net file hehe Very Happy
Private Nachricht senden Benutzer-Profile anzeigen
 
steve
Ehrenmitglied

Ehrenmitglied



Beiträge: 1.993
Anmeldedatum: 03.09.07
Wohnort: Wien
Version: R2022a
     Beitrag Verfasst am: 11.07.2022, 21:11     Titel:
  Antworten mit Zitat      
Hallo Basti,

einen Fehler den ich im anderen Beitrag unkommentiert korrigiert hatte, sehe ich hier auch: Du hast im code zweimal einen Ordnerpfad angegeben. Im ersten Fall hast du korrekt "\\" verwendet um "\" als Ausgabe zu bekommen, im zweiten Fall jedoch nicht. Dort kommt dann "\P" vor und diesen special character kennt Matlab eben nicht. Daher dann auch die Fehlermeldung.

Viele Grüße
Steve
_________________

>> I told me to.

____________________________________
goMatlab-Knigge - dran gehalten?!
Schon in den FAQ gesucht?
Ist vielleicht bei den Skripten oder den Tutorials was für dich dabei?
Private Nachricht senden Benutzer-Profile anzeigen
 
Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.
Du kannst Dateien in diesem Forum posten
Du kannst Dateien in diesem Forum herunterladen
.


goMatlab ist ein Teil des goForen-Labels
goForen.de goMATLAB.de goLaTeX.de


 Impressum  | Nutzungsbedingungen  | Datenschutz  | Werbung/Mediadaten | Studentenversion | FAQ | goMatlab RSS Button RSS


Copyright © 2007 - 2022 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks
Partner: LabVIEWforum.de

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.