Struct contents reference from a non-struct array object

  • Topic: MATLAB 
  • Thread starter quasarLie
  • Start date
  • Tags Tags
    Array Reference
11 replies · 5K views · last reply
quasarLie
Messages
50
Reaction score
0
Hello,
i need help with my code please , i have a file named 'bic' which contain only 2 columns . I want to plot this two columns.
Matlab:
Data=importdata('bic.dat');
g=Data.data(:,2)
r=Data.data(:,1);
delta=r-g;

plot(r,delta,'b*');
And i have this error
struct contents reference from a non-struct array object.
A sample of my columns
20.88 20.391
19.624 19.661
19.218 19.313
20.158 19.689
20.759 20.348
20.30 19.789
20.666 20.813
19.927 19.696
21.139 20.162
20.39 20.568
20.386 20.552
21.112 21.096
20.13 20.193
19.497 19.354
20.851 20.795
19.505 19.534
20.253 20.634
20.555 20.176
20.94 21.022
20.495 20.101
20.748 20.499
19.6 18.691
20.377 20.026
20.017 19.610
Thanks
 
importdata does not make a structure. It makes an array. Use " g = Data(:,2)" and " r = Data(:,1)"
 
thanks a lot, do you know how can I use this equation in the code
g=0.97*r+0.39
 
quasarLie said:
thanks a lot, do you know how can I use this equation in the code
g=0.97*r+0.39
I don't understand. Use it for what? If that is a regression equation, then you can add something like this to determine the errors for each point of g:
Code:
g2=0.97*r+0.39
err = g - g2
 
Yes it s a linear regression. i tried what you said but it does not work.
I did this code for the same file to plot the two columns but i don t know how to use the equation
Matlab:
fidi = fopen('bic.dat');
t = textscan(fidi, '%f%f', 'Delimiter',',');
fclose(fidi);
x=t{1};
y=t{2};
delta= x-y;
figure(1)
plot(y, delta, 'k*')
xlabel('\bfg')
ylabel('\bfr-g')
 
The code I suggested executes for me at the end of the code below. That code is the correction of your original post. But it's not clear to me what this is supposed to be doing. Is g the original data and r the regression estimates? I can not help if I have to guess at what you have already done and at what you want to do. All I can do is suggest (possibly meaningless) code that will not abort.

Code:
Data=importdata('bic.dat');
g=Data(:,2)
r=Data(:,1);
delta=r-g;

plot(r,delta,'b*');
g2=0.97*r+0.39;
err = g-g2
 
Yes I tried it for this code.
I want the equation of the line in form g2=0.97*r+0.39 to appear on my scatter plot
Thanks for your help
 
You can do multiple plots in one plot command as the examples of @DrClaude 's link shows or you can hold a plot and use other plot commands.

I suspect that you want something like this:
Code:
Data=importdata('bic.dat');
g=Data(:,2)
r=Data(:,1);

hold off;
plot(r,g,'b*');
hold on;
g2=0.97*r+0.39;
plot(r,g2);
 
Scatter plot of black asterisk markers with x-axis from 15 to 22 and y-axis from -25 to 10; most points form a dense band between about 0 and 4 on the y-axis, with a sparse cluster near y = -19 to -21 at x between 17 and 21.

With the equation the code give me this, and it s not correct
MATLAB scatter plot of black asterisk markers against a red straight line. Horizontal axis labelled S(GAIN) from 0 to 25; vertical axis labelled with a partly cut-off label and ticks from -25 to 25. Markers form a dense cluster near x=15 to 22, y=-5 to 6, and a small group near x=18 to 21, y=-17 to -21.
 
Attachments
  • Scatter plot of black asterisk markers with x-axis from 15 to 22 and y-axis from -25 to 10; most points form a dense band between about 0 and 4 on the y-axis, with a sparse cluster near y = -19 to -21 at x between 17 and 21.
    upload_2018-4-25_15-46-48.png
    4.9 KB · Views: 1,271
  • MATLAB scatter plot of black asterisk markers against a red straight line. Horizontal axis labelled S(GAIN) from 0 to 25; vertical axis labelled with a partly cut-off label and ticks from -25 to 25. Markers form a dense cluster near x=15 to 22, y=-5 to 6, and a small group near x=18 to 21, y=-17 to -21.
    upload_2018-4-25_15-47-38.png
    3.5 KB · Views: 1,234
and i want something like this
Scatter plot of a dense black point cloud shaped like a tapered cone opening to the right, with white contour lines around its densest core and a red horizontal reference line at zero on the vertical axis; two small red rectangles mark points near the upper left.

This is the code that i am using
Matlab:
fidi = fopen('bic.dat');
t = textscan(fidi, '%f%f', 'Delimiter',',');
fclose(fidi);
x=t{1};
y=t{2};
delta= x-y;figure(1)
plot(y, delta, 'k*')

y2=0.97*x+0.39
hold on;
plot(x,y2,'red')
I tried with yours and it s the same problem
 
Attachments
  • Scatter plot of a dense black point cloud shaped like a tapered cone opening to the right, with white contour lines around its densest core and a red horizontal reference line at zero on the vertical axis; two small red rectangles mark points near the upper left.
    upload_2018-4-25_15-50-57.png
    9.1 KB · Views: 1,248
Yes. You are mixing the plot of the errors, delta, with the plot of the estimator, y2. They are not on the same scale. The red line on the plot that you say you want is just the x axis. There is no need to plot y2.

If I am wrong about this, then it is because I still don't understand what you are trying to do and can not help you.