【发布时间】:2012-05-23 13:30:46
【问题描述】:
谁能告诉我为什么会收到这个错误—— ???从单元格转换为时发生以下错误 双倍的: 错误使用 ==> 双 无法从单元格转换为双精度。
==> 测试中的错误 18 CX(end+1,:) = temp(1);
代码如下:
file = fopen('C:\Program Files (x86)\Notepad++\testFile.txt'); % open text file
tline = fgetl(file); % read line by line and remove new line characters
%declare empty arrays
CX = [];
CY = [];
CZ = [];
while ischar(tline) % true if tline is a character array
temp = textscan(fid,'%*s%f%f%f','Delimiter',',<>'); % loads the values from all rows with the specified format into the variable data
CX(end+1,:) = temp(1);
CY(end+1,:) = temp(2);
CZ(end+1,:) = temp(3);
tline = fgetl(file);
end
fclose(file); % close the file
plot3(CX, CY, CZ) % plot the data and label the axises
xlabel('x')
ylabel('y')
zlabel('z')
grid on
axis square
【问题讨论】:
-
如果你在错误之前中断并在命令行中输入 temp(1),ans 是什么类型?它是单元格数组还是双精度数组。我假设 CX 是一个双数组?