Management of string elements from a text file

조회 수: 4 (최근 30일)
cbh0307
cbh0307 2017년 11월 28일
댓글: cbh0307 2017년 11월 29일
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
cbh0307
cbh0307 2017년 11월 29일
I will attach a picture here:
cbh0307
cbh0307 2017년 11월 29일
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. =)

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by