How to store the strings in For loop in subsequent rows of an cell
2 views (last 30 days)
Show older comments
Hi ,
I am working with the strings in For loop and I want to store the data recieved in each iteration into subsequent rows of an array here's the code I am using following code :
clc; clear all ;
fid = fopen('nid_file_data.txt') ; % open the text file
S = textscan(fid,'%s'); % text scan the data
fclose(fid) ; % close the file
S=S{1};
N = cellfun(@(x)str2double(x), S); % convert the cell array to double
% Remove NaN's which were strings earlier
N(isnan(N))=[];
L = length(S)
for i=1:L,j=1:L-1;
str = S{i};
w = split(str,";");
y = w(4,1);
ln = strlength(y);
z = insertAfter(y,ln,"C1");
w(4,1) = z;
w;
newstr = strjoin(w,";");
newstr
end
In output , I am getting newstr = "x" (some random string)
newstr = "y"
I want the output to be , newstr = {''x''
"y"
}
To summarize , I want each value of of newstr in subsequest iteration to be stored in subsequent rows.
0 Comments
Accepted Answer
Voss
on 26 Jun 2022
% newstr = strjoin(w,";"); % instead of this
newstr{i,1} = strjoin(w,";"); % do this
More Answers (0)
See Also
Categories
Find more on Data Type Conversion 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!