이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Sorting maximum value array by same date and time
조회 수: 2 (최근 30일)
이전 댓글 표시
I have an array of very large size 708273*3,the first and second column representing time and date respectively. Each time and date have many values. I need to find out maximum value from that. I have no idea with how to short those value from excel. Sample data file name "test1".
Any help will be highly appreciated.
With best regards,
Somnath
댓글 수: 1
답변 (1개)
Ameer Hamza
2020년 5월 28일
Try this
T = readtable('test1.xlsx');
grps = findgroups(T.Time, T.Date);
max_vals = splitapply(@max, T.Value, grps);
T.MaximumValue = max_vals(grps);
writetable(T(:,'MaximumValue'), 'test1.xlsx', 'Range', 'D1')
댓글 수: 24
SOMNATH MAHATO
2020년 5월 28일
Dear Ameer,
Thank you for your responce.
But this program is not working.
If possible can you send a screen short of your program. If you want more sample data, i can share with you.
regards,
Somnath
SOMNATH MAHATO
2020년 5월 28일
if possible can you send the details code in my email somnathmahato1@gmail.com. i am a new user in matlab.
Ameer Hamza
2020년 5월 28일
In MATLAB, the file name must not contain spaces. Remove the spaces from the name of the script and the use green button in the toolbar to run the code.
Ameer Hamza
2020년 5월 28일
You haven't changed the name of your script. Change it from "maximum elevaltion angle short.m" to something else, and it should not have spaces in its name.
SOMNATH MAHATO
2020년 5월 28일
this error shows:
Warning: Variable names were modified to make them valid MATLAB identifiers.
Undefined function or variable 'findgroups'.
Error in test (line 2)
grps = findgroups(T.Time,T.Date);
Ameer Hamza
2020년 5월 28일
Try this
T = readtable('test2.xlsx');
temp = num2str(T.Time, 16);
temp = mat2cell(temp, ones(size(temp,1),1), size(temp,2));
[~, ~, grps] = unique(strcat(temp, T.Date));
max_vals = splitapply(@max, T.Value, grps);
T.MaximumValue = max_vals(grps);
writetable(T(:,'MaximumValue'), 'test2.xlsx', 'Range', 'D1')
Ameer Hamza
2020년 5월 28일
Try this
T = readtable('test2.xlsx');
temp = num2str(T.Time, 16);
temp = mat2cell(temp, ones(size(temp,1),1), size(temp,2));
[~, ~, grps] = unique(strcat(temp, T.Date));
u_grps = unique(grps);
max_vals = zeros(numel(u_grps), 1);
for i=1:numel(u_grps)
max_vals(i) = max(T.Value(grps==u_grps(i)));
end
T.MaximumValue = max_vals(grps);
writetable(T(:,'MaximumValue'), 'test2.xlsx', 'Range', 'D1')
SOMNATH MAHATO
2020년 5월 28일
This error shows
• The workbook you are trying to save has the same name as a currently open workbook.
Help File: xlmain11.chm
Help Context ID: 0
Error in test (line 11)
writetable(T(:,'MaximumValue'),'test.xlsx','Range','D1')
SOMNATH MAHATO
2020년 5월 28일
When, i have select the hole data file... its can't short properly. Can please you check it.
Ameer Hamza
2020년 5월 28일
Try this. You may need to verify if the output is correct
T = readtable('test4.xlsx');
T = table2cell(T(:,1:3));
temp = num2str([T{:,1}].', 16);
temp = mat2cell(temp, ones(size(temp,1),1), size(temp,2));
[~, ~, grps] = unique(strcat(temp, T(:,2)));
u_grps = unique(grps);
max_vals = zeros(numel(u_grps), 1);
for i=1:numel(u_grps)
max_vals(i) = max([T{grps==u_grps(i), 3}]);
end
T = table(max_vals(grps), 'VariableNames', {'MaximumValue'});
writetable(T(:,'MaximumValue'), 'test4.xlsx', 'Range', 'D1')
SOMNATH MAHATO
2020년 5월 28일
Data start time and date 12:28:09 PM and 22-05-2020
Data end time and date 12:30:02 and 23-05-2020
according time and date ,data haven't shortlisted. I need to short the data like-
Time Date Maximum value
12:28:09 22-05-2020
12:30:02 23-05-2020
i can't short my data in the above format
Ameer Hamza
2020년 5월 28일
Yes, it seems possible, but the first column of the excel file is in some custom format, which is not recognized by MATLAB. You may first need to change the data type of the first column in Excel and then follow the code in my comment to only save each maximum value once.
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
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)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)