I try to read a text files with 20×20 data into variable C, and attempt to plot a histogram on the left Y-axes, and a ecdf/ksdensity on the right X-axes.
Using textscan, the data is read into a 400×1 array. However, when I tried to call plotyy to plot histogram, the code belows return
Error using plot
Vectors must be the same lengths.
Error in pt (line 11)
axes = plotyy(x,C{1},x,C{1});
I guess it is due to C{1}. But have no clue on how to resolve it. I am new to matlab, would anyone point out the correct way to perform the above operations?
fid = fopen('t1_error.txt','r');
C = textscan(fid, '%.3f');
fclose(fid);
disp(C{1});
x = -1:7; % <-- change to x = length(C{1}); then histogram is plotted.
axes = plotyy(x,C{1},x,C{1});
hold on
hist(axes(1), C{1}, x);
ylim(axes(1),'auto');
set(axes(1),'mode','auto');
hold off
The length of
xdoes not equal the length ofC{1}. Tryx = 1:length(C{1})orx = -1:8/length(C{1}):7.