スクリプトの何行目に何が書かれているかを特定する方法はありますか?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
KO
am 20 Dez. 2023
Kommentiert: Smith David
am 15 Jan. 2024
スクリプトの行数を特定し、その行に書かれているテキスト情報を出力することができる関数はありますか?
1 Kommentar
Smith David
am 15 Jan. 2024
スクリプトの特定の行に書かれているテキスト情報を取得するための簡単な方法はあります。以下は、MATLABの例ですが、他のプログラミング言語でも同様のアプローチが可能です。
function lineText = getScriptLine(filePath, lineNumber) % ファイルを開く fileID = fopen(filePath, 'r'); % 行ごとにセル配列に読み込む lines = textscan(fileID, '%s', 'Delimiter', '\n'); lines = lines{1}; % ファイルを閉じる fclose(fileID); % 指定された行が存在するか確認 if lineNumber <= numel(lines) % 指定された行のテキストを取得 lineText = lines{lineNumber}; else lineText = '指定された行は存在しません。'; end end
この関数を使用すると、特定のファイルと行数を指定して、その行に書かれているテキスト情報を取得できます。例えば、getScriptLine('yourScript.m', 10)とすると、'yourScript.m'の10行目のテキスト情報が取得されます。他のプログラミング言語でも同様のロジックを使用できます 漫画ロウ。
Akzeptierte Antwort
Dyuman Joshi
am 20 Dez. 2023
%Using dbtype on the built-in max() function
dbtype max.m
4 Kommentare
Atsushi Ueno
am 20 Dez. 2023
%Using dbtype on the built-in max() function
% dbtype max.m 5:7"
dbtype('max.m','5:7');
% dbtype max.m 5
dbtype('max.m','5');
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu スプレッドシート finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!