Mis-type append problem
1 次查看(过去 30 天)
显示 更早的评论
Hi guys,
I give an error when i try to append my values to arrays that ı create before while loop like that:
>> tryy
15.5023.758.0017.005.5019.0024.002.507.5011.0013.003.7525.009.7522.0018.006.0012.502.0021.50
2158.701678.152316.002061.302207.501708.301784.702575.002357.902256.702165.202399.551779.802336.751765.302053.502414.402200.502654.201753.70
Error using scatter (line 44)
Must supply X and Y data as first arguments.
Error in tryy (line 21)
scatter(x,y)
I think the problem involves w/ the my values type after when i append them to list because after i append them to list when i call as i.e x(4) they return to me 5 as an integer it has to return 5.50 as float .
This is propellant.csv
Thank You
fileID=fopen('propellant.csv');
y=[];
x=[];
counter=0;
while ~feof(fileID)
counter=counter +1;
tline=fgetl(fileID);
if counter > 1
newStr= split(tline,",",2);
a=newStr{2};
b=newStr{1};
x=[x a]; % I am tryin to append array these are my values as a to x and b to y
y=[y b];
end
end
disp(x);
disp(y);
scatter(x,y) % this is line 21
0 个评论
回答(1 个)
Jan
2021-5-9
编辑:Jan
2021-5-9
The problem is, that you provide CHAR vectors, but scatter requires numerical arrays.
readtable would be smart, but this works also:
fileID = fopen('propellant.csv');
fgetl(fileID); % Skip header
data = fscanf(fileID, '%g,%g', [2, inf]);
fclose(fileID);
scatter(data(1, :), data(2, :));
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!