Plotting function, which includes a sum

1 view (last 30 days)
Hey,
I am trying to plot the structure function of the temperature of measured data. The Data is in a netcdf. file. I am trying to calculate the sum over k and then plot it over x.
This is my code:
startLoc = [497870 536410];
ncread('030608_nc.100Hz_data1','Tt',startLoc);
Temp=ncread('030608_nc.100Hz_data1','Tt');
I
x=[0:10:10000];
k=[497870,536410];
syms k x
f= matlabfunction(symsum((Temp(k)-Temp(k+x)).^2,k,497870,536410));
plot(x,y);
I then get the following Errors:
>> Sum
Error using internal.matlab.imagesci.nc/read (line 554)
Wrong number of input arguments.
Error in ncread (line 66)
vardata = ncObj.read(varName, varargin{:});
Error in Sum (line 3)
ncread('030608_nc.100Hz_data1','Tt',startLoc);
Thanks for your help :)
  1 Comment
Jonas Reibenspies
Jonas Reibenspies on 26 Sep 2021
I face new errors:
Error using sym/subsindex (line 845)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic
variables, and function body must be sym expression.
Error in Sum (line 12)
f= matlabfunction(symsum((Temp(k)-Temp(k+x)).^2,k,497870,536410));

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 26 Sep 2021
When you provide a start value, you also have to provide a count -- even if you just provide inf as the count.
  6 Comments
Jonas Reibenspies
Jonas Reibenspies on 27 Sep 2021
thanks, that helped.
Altough I now get a new error:
Matrix dimensions must agree.
Error in Sum>@(x)reshape(sum((Temp(k(1):k(2))-Temp((k(1)+k(2)+x(:)))).^2,2),size(x))
Error in Sum (line 12)
y = f(x);
Walter Roberson
Walter Roberson on 27 Sep 2021
Your setup is suspect. Suppose you had read in all of the data, then examining your desired
f= matlabfunction(symsum((Temp(k)-Temp(k+x)).^2,k,497870,536410));
with x having a minimum value of 0 maximum value of 10000, then you the indices of the Temp values being subtracted would range from 497870+0 to 536410+10000 which is a span of 48541 items. But your count is count = [38540]; which is 10001 short . Note that 497870:536410 is 38541 items.
What is the index of the first item in Temp(k) that is to appear on the left side of the subtraction? What is the index of the last item in Temp(k) that should appear on the left side of the subtraction? What is the index of the last item in Temp(k+x) that should appear on the right side of the subtraction? Last-on-right - first-on-left + 1 is the count of items that you need to read in (we can worry about fixing up the indexing once the correct number of items is retrieved.)

Sign in to comment.

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!