I am getting the error along the lines of "Index exceeds number of array elements" and I am not sure how to fix it
1 次查看(过去 30 天)
显示 更早的评论
clc;
clear;
fileReader = fopen('datafile_5.csv','r');
index = 1;
while ~ (feof(fileReader))
line = fgets(fileReader);
tweet_info = struct();
split_values = strsplit(line, '"');
tweet_info(index).sent = string(split_values(2));
tweet_info(index).content = string(split_values(12));
tweet_info
index = index + 1;
end
MatLab says the error occurs in the line that says tweet_info(index).sent = string(split_values(2));
4 个评论
DGM
2021-4-25
Look at the variable line. If you're expecting it to have multiple fields (e.g. sent, content) and it doesn't follow the expected format, then you'll have to figure out what the line means conceptually. It might mean that you skip that line, or maybe you'd parse it differently.
Walter Roberson
2021-4-25
In particular, your existing code does not skip any initial header line that might be there.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!