import txt file in matlab
1 view (last 30 days)
Show older comments
I failed to import the attached txt which I need it to be read with the below function
which converts it into another data shape. I do not know what seems to be the problem. Any ideas?
function FBW = get_FBW(Ftable)
d = importdata(Ftable);
for i = 2:size(d.data,1) % do each row separately
rowdat = d.data(i,:);
rowdat = rowdat(~isnan(rowdat));
col = (rowdat(1:2:end-1));
val = rowdat(2:2:end);
nframes = col(end);
FBW(i-1,:) = zeros(1,nframes);
for j = 2:length(col)
if col(j) - col(j-1) >0
slope = (val(j) - val(j-1)) ./ (col(j) - col(j-1));
for k = 0:col(j)-col(j-1)
FBW(i-1, (col(j-1)+k)) = val((j-1)) + k*slope;
end
end
end
end
0 Comments
Accepted Answer
Image Analyst
on 19 Jun 2024
It looks like just a simple matrix of numbers. Try readmatrix
d = readmatrix(Ftable)
3 Comments
Stephen23
on 19 Jun 2024
Edited: Stephen23
on 19 Jun 2024
d = readmatrix('Ftable.txt')
and remove ".data" from your code. Avoid IMPORTDATA.
for i = 2:size(d,1) % do each row separately
rowdat = d(i,:);
rowdat = rowdat(~isnan(rowdat));
col = (rowdat(1:2:end-1));
val = rowdat(2:2:end);
nframes = col(end);
FBW(i-1,:) = zeros(1,nframes);
for j = 2:length(col)
if col(j) - col(j-1) >0
slope = (val(j) - val(j-1)) ./ (col(j) - col(j-1));
for k = 0:col(j)-col(j-1)
FBW(i-1, (col(j-1)+k)) = val((j-1)) + k*slope;
end
end
end
end
FBW
More Answers (1)
Taylor
on 18 Jun 2024
The problem is that "d" is not a structure so dot indexing does not apply.
2 Comments
Taylor
on 18 Jun 2024
Removing ".data" from the function should fix it (though I'm not entirely clear on the purpose of the function). There may be a better way to do what you're aiming for if you can clarify the goal of your function.
See Also
Categories
Find more on Desktop 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!