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
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by