Unequal left and right sides of matrix

1 回表示 (過去 30 日間)
Eric Williams
Eric Williams 2022 年 7 月 15 日
コメント済み: dpb 2022 年 7 月 20 日
% get parameters, allocate memory (I'm not having issues with this)
tiledimensions = 5000
tiledimensions = 5000
cornerUlLat = 39.2369
cornerUlLat = 39.2369
tiledimensions = 5000;
cornerUlLat = 39.2369;
nextlatpixel_1310 = 39.2366153;
tile1310_lat = zeros(5000);
delta_lat = 0.0002847;
% make matrix (here is where I'm confused)
tile1310_lat(:,1) = [cornerUlLat; nextlatpixel_1310];
Unable to perform assignment because the size of the left side is 5000-by-1 and the size of the right side is 2-by-1.
for i = 2:tiledimensions
tile1310_lat(:,i) = tile1310_lat(:,i-1) - delta_lat;
end
tile1310_lat;
I'm trying to make a 5000x5000 matrix of latitude values. The final product I want is for the latitudes to change going down the same column, but be the same across the same row. For example, this would look like:
39, 39, 39...
38, 38, 38....
I know what my delta needs to be and I think the for loop I have now would make the latitude values changing going down the column, but I want to copy each column across to the 5000th column so that I can have a latitude value for each pixel. I want to do the same thing for longitude later, but with the rows changing by delta_long and the columns staying the same (since longitude is x).
longitude:
104, 103, 102...
104, 103, 102...
My veryyyyy end goal is to have three matricies that are all 5000 by 5000: one for latitude, one for longitude, and one for my Landsat image data, then combine them into one matrix.
How would I copy each respective value list across and fix this error?

採用された回答

dpb
dpb 2022 年 7 月 15 日
編集済み: dpb 2022 年 7 月 15 日
Going at it hard way...use MATLAB vector operations --
M=cornerUlLat-[0:tiledimensions-1].'*delta_lat; % create first vector
M=repmat(M,1,tiledimensions); % and duplicate it
Gives you
>> whos M
Name Size Bytes Class Attributes
M 5000x5000 200000000 double
>> M(1:5,1:10)
ans =
39.2369 39.2369 39.2369 39.2369 39.2369 39.2369 39.2369 39.2369 39.2369 39.2369
39.2366 39.2366 39.2366 39.2366 39.2366 39.2366 39.2366 39.2366 39.2366 39.2366
39.2363 39.2363 39.2363 39.2363 39.2363 39.2363 39.2363 39.2363 39.2363 39.2363
39.2360 39.2360 39.2360 39.2360 39.2360 39.2360 39.2360 39.2360 39.2360 39.2360
39.2358 39.2358 39.2358 39.2358 39.2358 39.2358 39.2358 39.2358 39.2358 39.2358
>>
  2 件のコメント
Eric Williams
Eric Williams 2022 年 7 月 20 日
Yes! That worked! This method is for sure some big boy code, which I'm not super familiar with. I am now working on getting my longotude matrix, which is the same dimensions as this, except the values change by row rather than going down the column.
longitude:
104, 103, 102...
104, 103, 102...
Do you know how I could make this? I see that you used the apostrophe to transpore. I removed the apostrophe in hopes that it would work, but I got a 2x5000 matrix that changes down the column rather than left to right across the rows.
Thank you and here's what I have so far:
M2=cornerUlLon-[0;tiledimensions-1].*delta_long; % create first vector
M2=repmat(M2,1,tiledimensions); % and duplicate it
% try a comma instead of a semicolon or some other punctuation that will
% make it change by row?????
dpb
dpb 2022 年 7 月 20 日
Think about what you're building -- the first case needed to build a column vector to replicate; look at what the colon operator builds...
>> M=[0:tiledimensions-1];
>> whos M
Name Size Bytes Class Attributes
M 1x5000 40000 double
>> format short, format compact
>> M(1:10)
ans =
0 1 2 3 4 5 6 7 8 9
>>
and you see colon (:) build a row vector -- so, we must transpose it to replicate it horizontally for the duplicates.
Now you want to duplicate a row vector going down -- so, the first idea is correct, don't transpose the original output; keep it as a row vector. But, whereas we made 1 copy vertically and tiledimension copies horizontally, now you need to do the reverse -- make the copies by row but only one copy wide --
M2=repmat(M2,tiledimensions,1); % and duplicate it
It helps when playing with this stuff to use small toy-sized arrays of 10 or so elements max so that you can see the results conveniently in the command window while you work it out...

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by