Help doing array to display values on map

1 visualizzazione (ultimi 30 giorni)
desert_scientist90
desert_scientist90 il 25 Ott 2019
Risposto: Deepak il 13 Gen 2025
Hi I am trying to do an array that will calculate the mean value of the high composite minus the low composite divided by two. After that I am trying to do a t-test of each observation to be able to display it in a map. I started my array like this but matlab is giving me multiple error messages. My dataset is x=141,y=71 and t=38. I have to make this array work for the 38 years. the average of my high composite is 1.69 and the low -1.29 .Any help will be appreciated.
rain(141,71,38);
for j1=71
for i1=141
zm1=(i,j)=precip(i,j,1;);
end
end

Risposte (1)

Deepak
Deepak il 13 Gen 2025
We can achieve the calculation of the mean value and subsequent t-test for each observation in a 3D dataset by iterating through each spatial coordinate in the dataset. For each location, extract the time series data and perform a one-sample t-test against a predefined mean value, which is the average of the high and low composites. The results of these tests are stored in a matrix, allowing us to visualize the spatial distribution of p-values across the dataset using a heatmap.
Below is the sample MATLAB code to achieve the same:
% Initialize the dataset if not already done
% Assume precip is your data matrix of size (141, 71, 38)
% precip = rand(141, 71, 38); % Example initialization
% High and low composite values
high = 1.69;
low = -1.29;
% Mean value calculation
mean_value = (high - low) / 2;
% Initialize result matrix for storing t-test results
t_test_results = zeros(141, 71);
% Iterate over each spatial location
for i = 1:141
for j = 1:71
% Extract the time series for each location
data_series = squeeze(precip(i, j, :));
% Perform a one-sample t-test against the mean value
[~, p] = ttest(data_series, mean_value);
% Store the p-value or test result
t_test_results(i, j) = p;
end
end
% Display the t-test results
% use imagesc or a similar function to display the map
imagesc(t_test_results);
colorbar;
title('P-value Map from T-test');
xlabel('Longitude Index');
ylabel('Latitude Index');
Please find attached the documentation of functions used for reference:
I hope this helps in resolving the issue.

Community Treasure Hunt

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

Start Hunting!

Translated by