Why are the values in my matrix being divided by 1e^3?

조회 수: 10 (최근 30일)
Oscar Zampi
Oscar Zampi 2021년 2월 15일
댓글: Walter Roberson 2021년 2월 15일
Hi, I have the piece of code as shown below, when the matrix A is displayed, each value in it has been divided by 1e^3. I cant seem to figure out why, does anyone have any ideas?
clear all
clc
[ortho, cmap] = imread('Oban.TIF');
ortho = uint16(ortho);
count1 = 0 ;
peaks = zeros([],3) ; % to store i,j,ortho(i,j) in respective columns
sz = size(ortho);
md= median(ortho);
pks = zeros(sz(1),sz(2));
for i =2:sz(1)-1
for j =2:sz(2)-1
if ortho(i-1,j) < ortho(i,j) & ...
ortho(i+1,j-1) < ortho(i,j) & ...
ortho(i,j-1) < ortho(i,j) & ...
ortho(i,j+1) < ortho(i,j)
pks(i,j) = 1;
% fprintf("i=%d j=%d z=%d \n",i,j,ortho(i,j));
count1 = count1+1 ;
peaks(count1,:) = [i j ortho(i,j)] ;
end
end
end
% peaks
rand = randsample(1:length(peaks), 5);
randm = peaks(rand,:);
count2 = 0 ;
A = zeros([],3) ;
for m = 1:5
i = randm(m,1);
j = randm(m,2);
% fprintf('i is %d and j is %d \n',i,j);
R = worldfileread('concord_ortho_w.tfw', 'planar', size(ortho));
figure (5)
mapshow(ortho, cmap, R);
% LINE
Txx = i + 207000 ;
Txy = j + 909000;
Rxx = 210276;
Rxy = 910552;
hold on
h = plot([Txx Rxx],[Txy Rxy], 'b'); %draw line
Dx = Txx - Rxx;
Dy = Txy - Rxy;
Dsq = Dx^2 + Dy^2;
Dp = sqrt(Dsq);
Dm = Dp*25;
Dkm = Dm/1000;
Distance = string(Dkm);
text(Rxx, Rxy, 'Tx','Color','red','FontSize',14)
text(Txx, Txy, Distance,'Color','red','FontSize',14)
x = [Txx Rxx];
y = [Txy Rxy];
N = 20;
xi = linspace(x(1), x(2), N+1); %segment the line into n segments
yi = interp1(x, y, xi, 'linear');
Q = N ;
DistReso = Dm/Q;
plot(xi(2:end-1), yi(2:end-1), 'bp')
Elevationm = zeros(1,Q+1); %before the loop
for P = 1:Q %state values
format long
imag=imread('Oban.tif');
PointPx = Txx + (P*(Rxx-Txx)/N);
PointPy = Txy +(P*(Rxy-Txy)/N);
SubPlotxPRound = round(PointPx);
SubPlotyPRound = round(PointPy);
format long
ElevPx = (PointPx- 207000);
ElevPy = PointPy - 909000;
ElevPxRound = round(ElevPx);
ElevPyRound = round(ElevPy);
Elevationcm = imag(ElevPxRound,ElevPyRound);
Elevationm(1,P+1) = Elevationcm/100;
end
struct_Input = struct;
struct_Input.Frequency = 38000000000; % Frequency to calculate loss at (Hz)
struct_Input.Elevation = Elevationm; % terrain elevation profile, (list of points) (m)
struct_Input.Resolution = DistReso; % terrain input resolution (distance between points) (m)
struct_Input.TX_Height = 50; % Transmit antenna height above ground (m)
struct_Input.RX_Height = 200; % Recieve antenna height above ground (m)
struct_Input.eps = 4; % Soil dielectric
struct_Input.sgm = 50; % Surface conductivity
struct_Input.surfref = 260; % Surface refractivity
struct_Input.Climate = 5; % Climate, 1-Equitorial, 2-Continental Subtropical, 3-Maritime Tropical, 4-Desert
struct_Input.Polarization = 1; % 1 is vertical, 0 is horizontal.
struct_Input.Confidence = 0.95; % confidence for statistical analysis (.01 to .99)
struct_Input.Reliability = 0.9; % Reliability to calculate statistics for (.01 to .99)
myLRobj = CL_Propagation_RF_LR();
% myLRobj.test();
% struct_Output = point_to_point(myLRobj,struct_Input)
TS = 25;
dbloss = 361.6;
RS = TS - dbloss;
NF = -150;
SNR2 = RS - NF;
PL = dbloss;
F = -(0.5 * SNR2) + (0.5 * (PL/Dkm));
fprintf('i is %d, j is %d, fitness is %d. \n',i,j,F)
count2 = count2+1 ;
A(count2,:) = [i j F] ;
end
disp(A);

답변 (1개)

Walter Roberson
Walter Roberson 2021년 2월 15일
Give the command
format long g
and disp(A) again. I think you will see the values you expect.
The default set by MATLAB is format short. If you looked very carefully at the very beginning of the output of the display, it would have said
1e3 *
meaning that you were intended to mentally multiply all the displayed values by 1000 .
  댓글 수: 2
Oscar Zampi
Oscar Zampi 2021년 2월 15일
Yes that seems to have done the job - thank you for clarifying for me. It did say 1e3 * , is this jusr MATLAB doing its own thing?
Walter Roberson
Walter Roberson 2021년 2월 15일
It's a "feature"
format short is the default because it creates compact output, and a lot of the time people really don't need to know more than 5 digits of precision. 5 digits is good enough most of the time. Unfortunately, the assumption in the display routines is that all rows and columns have the same relative weight, so that if one value is 123456 and another value is 42, that the 42 barely rates a digit of output by comparison. However a lot of the time that doesn't hold, and different columns might have different scales or different starting points and using a common scale factor gives very wrong understandings of the data...

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

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by