Convert string to 256 Characters
6 次查看(过去 30 天)
显示 更早的评论
How to create the Matlab source text which will be equivalent to this Fortran text? The character variable must be 256 characterts long
Character*256 TEXT
TEXT = 'Unformatted Data Version='
Print*, TEXT
END
Thanks!
0 个评论
回答(2 个)
Walter Roberson
2024-9-27
编辑:Walter Roberson
2024-9-27
TEXT = sprintf('%256s', 'Unformatted Data Version=');
fprintf(FILEID, "%s\n", TEXT)
0 个评论
Ronit
2024-9-27
编辑:Ronit
2024-9-27
In MATLAB, you can convert a string to a fixed length by padding it with spaces or truncating it to ensure it is exactly 256 characters long by using the "pad" function.
text = 'Unformatted Data Version=';
textUpdated = pad(text, 256);
disp(textUpdated);
Here is the documentation link for "pad" function:
I hope it helps your query!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!