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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/612895/image.png)
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에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!