Mis-type append problem
Show older comments
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
Answers (1)
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 Comments
Ugur Sahin
on 10 May 2021
Jan
on 10 May 2021
You just swapped x and y. Try:
scatter(data(2, :), data(1, :));
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!