calculate the maximum of a series of values ​​in a large matrix

조회 수: 3 (최근 30일)
Victoria Pilar Quesada García
Victoria Pilar Quesada García 2023년 3월 21일
편집: Dinesh 2023년 3월 29일
I have this but it only applies to data with one row and many columns and I want to apply the same but to a matrix that has 485 rows and the same columns
clear all;close all
load("date 1*552262.mat")
data=sshobscorr
% determine total number of days of data
numDays = length(data)/24;
% reshape your temperature data so that you have a column for each day, with a row for each hour in the day
Tdata = reshape(data,24,numDays)
% calculate your min and max for each day
dailyMin = min(Tdata);
dailyMax = max(Tdata);
  댓글 수: 2
dpb
dpb 2023년 3월 21일
편집: dpb 2023년 3월 22일
485/24, mod(485,24)
ans = 20.2083
ans = 5
isn't even to be able to assume one row/hour in a day with that dataset.
So, what's the exact content of the file; from whence is one to be able to determine what day/time corresponds to a given element in the array?
dpb
dpb 2023년 3월 23일
N=485*485, num2str(N/24,'%.3f'), mod(N,24)
N = 235225
ans = '9801.042'
ans = 1
IFF the file happens to be 485 x 485 hourly observations AND
  1. the first element begins at midnight of the first day AND
  2. the data were written sequentially by column, AND
  3. you throw away the one odd element at the end,
then and only then
...
data=data(:); % create long column vector of total number
data=data(1:end-mod(N,24)); % keep even multiple of 24
data=reshape(data,24,[]); % and now can reshape
dailyMinMax=[min(data);max(data)]; % put in an array for grins...
A zillion assumptions made, but with no other information to go on...

댓글을 달려면 로그인하십시오.

답변 (1개)

Dinesh
Dinesh 2023년 3월 29일
편집: Dinesh 2023년 3월 29일
Hi Victoria!
As per my understanding, Data is a 1D array of hourly temperatures. Assuming the same for the array with 485 rows and several columns, say ‘n’. Then we have 485 * n number of hours in total. A straightforward way to solve the problem is the following.
total_hours = 485 * n; % calculate total hours
days = total / 24; % get total days
remainder = mod(total,24); % number of hours that last day has
Total number of hours might not be multiple of 24. So, on last day we will not have complete information.Thus, we will calculate min and max separately for the last day.
data = data(:) % convert to 1D array
if remainder ~= 0 %if last day information has 5 hours, then find min and max of those 5 hours
minmax = [min(data(total_hours-remainder:end)), max(data(total_hours - remainder:end))]
end
data = data(1:total_hours - remainder)
data = reshape(data, 24, [])
dailyMin = [min(data), minmax(0)]
dailyMax = [max(data), minmax(1)]
If you do not want to convert the 2D array, then simply iterate over the rows.
for i= 1:485
row = data(i,:)
% if columns n % 24 ~= 0 then take care about calculating min and max
end
Hope this helps,
Thank you!

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by