Unequal left and right sides of matrix
1 次查看(过去 30 天)
显示 更早的评论
% get parameters, allocate memory (I'm not having issues with this)
tiledimensions = 5000
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];
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?
0 个评论
采纳的回答
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 个评论
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 Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!