错误:尝试访问数据(2,:);索引越界,因为 size(data)=[1,7129]
我有一个38行7130列的微阵列数据。我正在尝试读取数据,但仍然出现上述错误。
我调试了一下,读取数据时发现,我的是1x7129,而不是38x7130。我不知道为什么。我的第 7130 列包含字母,其余数据是数字。知道为什么会发生这种情况吗?
我的文件位于文本制表符分隔中,这是我用于读取文件的代码:
clear;
fn=32;
col=fn+1;
cluster=2;
num_eachClass=3564;
row=num_eachClass*cluster;
fid1 = fopen('data.txt', 'r');
txt_format='';
for t=1:col txt_format=[txt_format '%g '];
end
data = fscanf(fid1,txt_format,[col row]);
data = data'; fclose(fid1);
I have a micro-array data of 38 row and 7130 columns. I am trying to read the data but keeping having the above error.
I debugged and found when I read the data, I have a 1x7129 instead of a 38x7130. I don't know why. My 7130th column contains letters while the rest of the data are numbers. Any idea why this is happening?
My file is in text tab delimited and here is my code for reading the file:
clear;
fn=32;
col=fn+1;
cluster=2;
num_eachClass=3564;
row=num_eachClass*cluster;
fid1 = fopen('data.txt', 'r');
txt_format='';
for t=1:col txt_format=[txt_format '%g '];
end
data = fscanf(fid1,txt_format,[col row]);
data = data'; fclose(fid1);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用此代码来读取数据:
编辑
要将数据集分开进行训练和测试,请执行以下操作:
您还可以随机分离样本:
我还没有进行转置
data = data';
。如果必须的话,只需在上面的代码中切换行和列索引:
Try this code to read the data:
EDIT
To separate your dataset to training and test, do something like this:
You can also separate samples randomly:
I haven't done transposition
data = data';
.If you have to, just switch row and column indexes in the above code: