Cells detect and Cells numers in array
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hello,
I've got an array out of a scope simulation in simulink. In this array i've got the time in 1st column and the value of the signal in the 2nd. My max step size is 10sec. so the time data is from 0 to 1000 per 10 ( there is more values in time column but thats not the problem). I want to know what is the value of B1(the cell location as it is in excel) if A1=0. e.g. what is the value of the signal when time is 0 ? Then what is the value when the time is 60 sec and so on.
Thanks in advance !
채택된 답변
Star Strider
2021년 8월 3일
M1 = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/701747/1.xlsx')
M1 = 65926×2
0 232.6044
0.0000 232.6044
0.0000 232.6044
0.0000 232.6044
0.0000 232.6044
0.0000 232.6044
0.0001 232.6044
0.0003 232.6044
0.0015 232.6044
0.0074 232.6044
time_desired = [0, 10, 60, 90, 120, 180]; % Define As Desired
interpolated_signal = interp1(M1(:,1), M1(:,2), time_desired.', 'linear')
interpolated_signal = 6×1
232.6044
232.6119
232.6492
232.6716
232.6940
232.7388
figure
plot(M1(:,1), M1(:,2),'-b')
hold on
plot(time_desired, interpolated_signal, 'rs')
hold off
grid
xlabel('time')
ylabel('signal')
xlim([0 200]) % Restrict Axis View To Sho9w Detail

Make necessary changes to get the result you want.
.
댓글 수: 7
Thank you so much ! That was what i need. :)
i've one more difficult question.
Well i get what you make here with interp1, but how can i get the average of the data between the range ot the time.
What i mean is it the "time_desired = [0, 10, 60, 90, 120, 180];"
a What is the average value of the signal between 0 and 10 sec e.g. if there is 15 values between 0 and 10 sec. what is their average and then what is the average of the values between 10 and 60 sec and so on.
I will be so grateful if u can help with that one too!
Thank you alot!
As always, my pleasure!
The mean values claculation is a bit more complicated, however definitely possiible:
format shortG
M1 = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/701747/1.xlsx')
M1 = 65926×2
0 232.6
1.5214e-08 232.6
9.1282e-08 232.6
4.7162e-07 232.6
2.3733e-06 232.6
1.1882e-05 232.6
5.9425e-05 232.6
0.00029714 232.6
0.0014857 232.6
0.0074286 232.6
format short
time_desired = [0, 10, 42, 60, 90, 115, 121.5, 180]; % Define As Desired
interpolated_signal = interp1(M1(:,1), M1(:,2), time_desired.', 'linear')
interpolated_signal = 8×1
232.6044
232.6119
232.6358
232.6492
232.6716
232.6903
232.6951
232.7388
meanvals = zeros(numel(time_desired)-1,3);
N = 150; % Interpolation Length
for k = 1:numel(time_desired)-1
xv = linspace(time_desired(k), time_desired(k+1), N);
yv = interp1(M1(:,1), M1(:,2), xv);
meanvals(k,:) = [time_desired(k), time_desired(k+1), mean(yv)];
end
MeanIncrementValues = array2table(meanvals, 'VariableNames',{'Time_1','Time_2','Interval_Mean'})
MeanIncrementValues = 7×3 table
Time_1 Time_2 Interval_Mean
______ ______ _____________
0 10 232.61
10 42 232.62
42 60 232.64
60 90 232.66
90 115 232.68
115 121.5 232.69
121.5 180 232.72
figure
plot(M1(:,1), M1(:,2),'.-b')
hold on
plot(time_desired, interpolated_signal, 'rs')
hold off
grid
xlabel('time')
ylabel('signal')
xlim([0 200]) % Restrict Axis View To Show Detail

The interpolated times may not always correspond to times in the original data matrix (I added a few to emphasize that), so rather than computing the mean based on the increment between them, this creates a common interpolation length (‘N’), and then computes the average of the interpolated values. This approach also lends itself to calculating the mean slope, or linear, polynomial, or nonlinear regressions between the points.
.
Krasimir Terziev
2021년 8월 5일
편집: Krasimir Terziev
2021년 8월 5일
Hello again,
I'm so happy that u help me out! I will use this for my work for sure.
Just to tell you what disturbing me.
1st when i write this 2 rows :
test_results = average(M1(1:74,2)) - row 1
testi_results2 = average(M1(75:134,2)) - row 2
the 1st row give a different answer from the table of MeanIncrementValues
so i find out that's because somehow ( sorry im not good at coding) u ignores the value that are divided by 10 with a remainder other than 0. That is perfect for me !
the 2nd rows shows me again different answer
here i found out that the calculation of the 2nd average is takeing the 600 sec value e.g. when u make the 1st average u actually dont need to use the 0 sec value cuz it is already used in the last average calc.
so here is the same, when the average from 10 to 600 is made, it needs to make next average from 610 to 1200 because 600 is already taken in the last average calculation.
when i do this changes;
testi_results = average(M1(74:134,2)) - row 2
it gives me almost the same number ( only after 6 characters after the decimal point the numbers change) witch is totaly fine for me!
Thanks in advance!
If those little things are not change, its still fine because the relative error is small !
As always, my pleasure!
The end points are included in the mean value calculations by definition. You can use MATLAB indexing conventions to eliminate the first or last points in the calculations, if you want to.
That would be for example:
meanvals(k,:) = [time_desired(k), time_desired(k+1), mean(yv(1:end-1))];
to not include the last point in the calculation, or something similar to eliminate the first point ‘yv(2:end)’, or both ‘yv(2:end-1)’. Choose whatever works best for you.
.
Krasimir Terziev
2021년 8월 5일
편집: Krasimir Terziev
2021년 8월 5일
That was what i looking for !
Thank you so much! I can't describe how greatful I am.
Wish u best of luck and stay save!
Great!
As always, my pleasure!
You, too!
.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
