Management of string elements from a text file
4 views (last 30 days)
Show older comments
Hello ladies and gentlemen, I have encountered several problems when trying to read a text files and try to change it to text files with new format of display. I will simplify the table to make it clearer. The table somehow looks like this (without first column of titles):

and this table should be changed to new table that looks like this to be later saved in another text file:

The 'x' will be added behind to the hexadecimal address (string), and some of the hex data got only 1 content instead of 2 (empty space which should be considered as well)
I have tried in the first step of reading the data in string format %s, the codes look like these:
File_Input = 'C:\Users\Test.txt';
formatSpec = '%s %s %s %s %s';
Array_Old = textscan(fileID, formatSpec);
Array = zeros(numel(Array_Old{1, 1}), size(Array_Old, 2));
for i = 1:size(Array_Old,2)
for j = 1:size(Array_Old{1, i}, 1)
Array(j,i) = Array_Old{1, i}{j, 1};
end
end
fclose(fileID);
The Array_Old is 1x5 cell (there are vectors inside every 5 cells), while the Array is 5x5 double. I cannot pass the old value to the new value as it is double to cell. After that I try to use strings instead of zeros to create empty array for string, but encountered the problem:
Attempt to execute SCRIPT strings as a function:
C:\MATLAB\R2016a\toolbox\matlab\strfun\strings.m
It would be pretty much appreciated if anyone has a better insights on how to solve this problem. Thank you in advance.
6 Comments
Answers (0)
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!