Management of string elements from a text file

4 visualizzazioni (ultimi 30 giorni)
cbh0307
cbh0307 il 28 Nov 2017
Commentato: cbh0307 il 29 Nov 2017
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 Commenti
cbh0307
cbh0307 il 29 Nov 2017
I will attach a picture here:
cbh0307
cbh0307 il 29 Nov 2017
I have updated my MATLAB version from R2016a to R2017b and replace the following commands with the next one
Array = zeros(numel(Array_Old{1, 1}), size(Array_Old, 2)); % old
Array = strings(numel(Array_Old{1, 1}), size(Array_Old, 2)); % new
And the reading part of the data into string array worked perfectly. =)

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by