How to equalize dimensions to create scatter plot?

1 回表示 (過去 30 日間)
Nick Blom
Nick Blom 2022 年 6 月 15 日
回答済み: Anuj 2023 年 7 月 10 日
Hello,
I am trying to create a scatter plot of two types of data 1) temperature and 2) pesticide application rate. I downlaoded the data online as a netcdf (.nc) file. However, the two files have different dimensions. For the application rate the dimensions are 4306x1681x6 (Latitude, longitude, 3 years with High and low estimate). The temperature data has 720x360x120 (Latitude, longitude, years from 1901-2020).
If I try to use the following command for Temp = temperature and APR = application rate
scatter(Temp(:,:,120),APR(:,:,3))
it gives the following error
How do I adjust the dimensions without losing any data?
Thanks in advance,
Nick
  1 件のコメント
pragnan nadimatla
pragnan nadimatla 2023 年 7 月 6 日
As per my understanding, you want to equalise two dimensions of data in order to plot scatter plot.
Since the dimensions of the two data sets you have are not the same,you cannot directly use scatter command to plot them against each other. You have to perform some kind of preprocessing like interpolation to match dimensions.
One approach is to resample or interpolate pesticide data to match resolution of temperature data or vice versa. You can use MATLAB’s interp2 function to interpolate pesticide data to match temperature data and then use scatter plot to plot both of them.
Please refer to the following documentation on how to use interp2 function :
https://in.mathworks.com/help/matlab/ref/interp2.html?searchHighlight=interp2&s_tid=srchtitle_interp2_1

サインインしてコメントする。

回答 (1 件)

Anuj
Anuj 2023 年 7 月 10 日
Hi Nick,
To adjust the dimensions of the temperature and pesticide application rate data without losing any data, you need to ensure that the dimensions match for the scatter plot. Since the dimensions of the two datasets are different, you can reshape or interpolate the data to align them properly. Here's an approach you can follow:
Reshape the temperature data to match the dimensions of the pesticide application rate data. In this case, you need to resize the temperature data from 720x360x120 to 4306x1681x6. You can use the imresize3 function in MATLAB to achieve this.
resized_temp = imresize3(Temp, [4306, 1681, 6]);
Once you have resized the temperature data, you can now create the scatter plot using the reshaped temperature data and the pesticide application rate data.
scatter(resized_temp(:), APR(:));
By using resized_temp(:), you reshape the temperature data into a column vector to match the dimensions of the pesticide application rate data. This allows you to create a scatter plot between the two datasets.
Note: Reshaping or interpolating the data may introduce some interpolation artifacts or loss of precision. It's important to consider the nature of your data and the implications of any interpolation or resizing methods you use.
Or you can interpolate the temperature data to match the dimensions of the pesticide application rate data, you can use the interp3 function in MATLAB. This function performs 3D interpolation to resize the temperature data to the desired dimensions.
% Define the desired dimensions for the temperature data
desired_size = size(APR(:,:,3));
% Reshape the temperature data to match the desired dimensions
resized_temp = interp3(Temp, desired_size(2), desired_size(1), desired_size(3));
% Create the scatter plot using the interpolated temperature data and the pesticide application rate data
scatter(resized_temp(:), APR(:,:,3)(:));
In the code above, interp3 is used to interpolate the temperature data (Temp) to match the dimensions of the pesticide application rate data (APR(:,:,3)). The interp3 function takes the temperature data, the desired size (obtained from APR(:,:,3)), and performs the interpolation.
After interpolating the temperature data, you can create the scatter plot using the interpolated temperature data (resized_temp(:)) and the pesticide application rate data (APR(:,:,3)(:)). The (:) notation reshapes the data into column vectors to match the dimensions for the scatter plot.

カテゴリ

Help Center および File ExchangeSmoothing and Denoising についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by