Mac use strsplit happen question(Matlab 2020b)

code:
if( ~isempty( regexp(tline,'Atom .*has atomic number .*and mass ', 'once') ) )
str = strsplit( strtrim(tline), ' ')
end
input:' Atom 1 has atomic number 6 and mass 12.00000'
output:
1×9 cell array
Columns 1 through 5
{'Atom'} {'1tom'} {'hasm'} {'atomic'} {'number'}
Columns 6 through 9
{'6umber'} {'andber'} {'masser'} {'12.00000'}
The output is wrong!

3 Kommentare

Which version are you using?
tline = ' Atom 1 has atomic number 6 and mass 12.00000';
if( ~isempty( regexp(tline,'Atom .*has atomic number .*and mass ', 'once') ) )
str = strsplit( strtrim(tline), ' ')
end
str = 1×9 cell array
{'Atom'} {'1'} {'has'} {'atomic'} {'number'} {'6'} {'and'} {'mass'} {'12.00000'}
Dyuman Joshi
Dyuman Joshi am 17 Jan. 2024
Bearbeitet: Dyuman Joshi am 17 Jan. 2024
@Walter OP is using R2020b.
This is output when I ran the same code in my R2021a -
>> tline = ' Atom 1 has atomic number 6 and mass 12.00000';
if( ~isempty( regexp(tline,'Atom .*has atomic number .*and mass ', 'once') ) )
str = strsplit( strtrim(tline), ' ')
end
str =
1×9 cell array
{'Atom'} {'1'} {'has'} {'atomic'} {'number'} {'6'} {'and'} {'mass'} {'12.00000'}
I just installed R2020b and tested with the above code on an Intel Mac OS Sonoma. Output was as expected
str =
1×9 cell array
{'Atom'} {'1'} {'has'} {'atomic'} {'number'} {'6'} {'and'} {'mass'} {'12.00000'}

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

树果
树果 am 17 Jan. 2024
Verschoben: Dyuman Joshi am 17 Jan. 2024

0 Stimmen

Thank you all!I have script name ‘strsplit.m’ the same as the function 'strsplit'. I made a mistake!

1 Kommentar

Dyuman Joshi
Dyuman Joshi am 17 Jan. 2024
Verschoben: Dyuman Joshi am 17 Jan. 2024
Ah, that should be it.
Now, this should be a reminder to not name variables or scripts as the same as functions in MATLAB.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2020b

Gefragt:

am 17 Jan. 2024

Verschoben:

am 17 Jan. 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by