Plotting function, which includes a sum
이전 댓글 표시
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개)
Walter Roberson
2021년 9월 26일
0 개 추천
When you provide a start value, you also have to provide a count -- even if you just provide inf as the count.
댓글 수: 6
Jonas Reibenspies
2021년 9월 26일
Walter Roberson
2021년 9월 26일
Delete the syms k x but keep the assignment to k . Then
f = @(x) reshape(sum((Temp(k(1):k(2)) - Temp((k(1)+k(2)+x(:)))).^2,2), size(x));
y = f(x);
plot(x, y)
Jonas Reibenspies
2021년 9월 26일
Walter Roberson
2021년 9월 27일
Remember you ask to start reading at 497870, so that is the location that is going to be at offset 1 in the resulting array.
Use
k=[497870,536410] - startLoc + 1;
Jonas Reibenspies
2021년 9월 27일
Walter Roberson
2021년 9월 27일
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.)
카테고리
도움말 센터 및 File Exchange에서 Historical Contests에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!