Visually midway between two points on a x axis log scale [closed] - matlab

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
The follow plot shows my question:
I would like to add a line between the points of 1e-1 and 1e-2. So I thought just (1e-1+1e-2)/2.
But for a log scale that is not "midway".
How can I calculate the "visual" midway value between these, or any two points in this case? Code used is
clc; clear all;
y = logspace(-3,0,100);
x = y;
semilogx(y,x);
hold on
plot([1e-1 1e-1],get(gca,'YLim'),'k--');
plot([1e-2 1e-2],get(gca,'YLim'),'k--');
midway = (1e-1+1e-2)/2;
plot([midway midway],get(gca,'YLim'),'k--');
Thanks

a=1e-2
b=1e-1
midway = exp((log(a)+log(b))/2)
Take the log to get the positions in log scale, then do the math.
You could simplify that formula and you will end up with a geometric mean:
midway=sqrt(a*b)

Related

How to select the Figure to programmatically fit it to the screen in Matlab? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 6 years ago.
Improve this question
As mentioned in this question, one can open a new figure that is fit to the screen using the command
figure('units','normalized','outerposition',[0 0 1 1])
Assume now that some script has generated figures figure(1), figure(2) and figure(3) and you want to programmatically select figure(2) and fit it to the screen.
A possibility would be to use the mentioned command instead of figure inside the script that generates the figures, but assume that you cannot (or do not want to) modify this script. You really want to select one of the already existing figures. How would you do that?
It seems to be easier than I thought:
h=figure(2)
set(h,'units','normalized','outerposition',[0 0 1 1])

How do I integrate a vector in MATLAB [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to perform integration on a vector L but I don't know exactly what to use. I want to obtain a (the integral) as a vector that is the same size as NT.
clc;clear;
syms x
NT=input('NT=');
L=zeros(NT,1);
for i=1:NT
disp('Longeur de travée')
L(i)=input('L = ');
L(i)=L(i);
fa(i)=L(i).*x^2;
a(i)=int(fa)
end
An easy way would be to use trapz. If you have X and Y such that Y(i) = f(X(i)) (so Y contains the values of some function at the location X) then you simply do
I = trapz(X, Y)
In your case, you can do
I = trapz(L, fa)
I guess, looking at your code.
Note that you could use more advanced techniques, that will, in principle, give you a better result (because they are higher-order). This is just one method, but an easy one.

How to crop a region in LIDAR point cloud [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have 2 data set point cloud and I want to crop a part of them together.
Because of volume of them is too too large I couldn't crop them with below codes.
Can you help me to how can I crop them?
Used codes are:
selectedl=[];%% last pulse
for i=1:size(indexl)
selectl=lr(indexl(i),:);
selectedl=[selectedl;selectl];
end
selectedf=[];%% first pulse
for i=1:size(indexf)
selectf=fr(indexf(i),:);
selectedf=[selectedf;selectf];
end
Thank U all.
It is a bit difficult to understand what you want to do, as lr, fr, indexl and indexf are missing.
But assuming something like
lr = rand(5,3) ;
indexl = [2 5] ;
I would advise to allocate selectedl above the loop
selectedl = NaN(length(indexl),size(lr,2)) ;
for i = 1:length(indexl)
selectedl(i,:) = lr(indexl(i),:) ;
end
This might not be needed for this example, but if the data size becomes larger this will speed up the loop.

syntax of Iteration in K-mean Clustering With MATLAB [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
i have a problem with using the number of iteration in MATLAB.
i use this code but there is no change in the number of iteration:
Edit
this is my code...
clc;clear;close all;diary temp;
cluster_data=unifrnd(-3,+3,[100 2]);
optns = statset('MaxIter',500);
[idx,ctrs]=kmeans(cluster_data,3,'dist','city', ...
'display','iter','replicate',100,'options',optns);
figure
plot(cluster_data(idx==1,1),cluster_data(idx==1,2),'r.','MarkerSize',14)
hold on
plot(cluster_data(idx==2,1),cluster_data(idx==2,2),'b.','MarkerSize',16)
plot(cluster_data(idx==3,1),cluster_data(idx==3,2),'g.','MarkerSize',18)
plot(ctrs(:,1),ctrs(:,2),'kx',...
'MarkerSize',12,'LineWidth',2)
plot(ctrs(:,1),ctrs(:,2),'ko',...
'MarkerSize',12,'LineWidth',2)
legend('Cluster 1','Cluster 2','Cluster 3','Centroids',...
'Location','NW')
fid=fopen('temp');
dat=textscan(fid,'%s');
fclose(fid);
delete temp
dat=dat{1};
i1=find(~cellfun('isempty',strfind(dat,'sum')));
ie=find(~cellfun('isempty',strfind(dat,'iterations')));
i1=i1(1)+1;
Nd=str2num(dat{ie(1)-1});
ie=Nd*4+i1-1;
dat=reshape(str2num(strvcat(dat{i1:ie})),4,Nd)';
iter = dat(:,1) % <-- iterations
sm = dat(:,4) % <-- sum
figure
plot(iter,sm)
the issue is the number of iteration... how can i really increase the number of iteration?
however i increase the 'Maxiter' but no change appear.
You should use statset to change the number of iterations:
optns = statset('MaxIter',500);
And the call kmeans like this:
[idx,ctrs]=kmeans(cluster_data,3,'dist','city', ...
'display','iter','replicate',100,'options',optns);
Comment
The documentation for kmeans states:
MaxIter - Maximum number of iterations allowed. The default is 100.
So if you change the value of MaxIter it should be a number different from 100.

How to apply sliding window for subtracting two different images in matlab? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How to apply sliding window for subtracting two different images in matlab,
the window size must be 4X4,
please help me
i want to find similarity value between two different images.if A and B are two 2 images take difference between each 4x4 matrix of each A&B in sliding window manner
i tried a code ,i dont know whether it is correct or not
m=imread('index.jpeg');
sal=imread('salt.jpg');
salt=rgb2gray(sal);
ab=rgb2gray(m);
imshow(ab);
imh=size(ab,2);
imw=size(ab,1);
wh=4;
ww=4;
k=0;
disp(imh),disp(imw);
if 1
for j=1:imh+wh-1
for i=1:imw+ww-1
w1=ab(j:j+wh-1,i:i+wh-1,:);
w2=salt(j:j+wh-1,i:i+wh-1,:);
w3=w1-w2;
disp(w3);
disp('next mat');
end
k=k+1;
disp(k);
end
end
The upper bounds of your for-loops are the cause for your troubles.
You specify:
imh=size(ab,2);
imw=size(ab,1);
However, your for-loops have these conditions:
j=1:imh+wh-1
and
i=1:imw+ww-1
So you move past both the 'height' and the 'width' dimension.
Try this instead:
for j=1:imh-wh
for i=1:imw-ww
w1=ab(j:j+wh,i:i+wh,:);
w2=salt(j:j+wh,i:i+wh,:);
w3=w1-w2;
end
k=k+1;
end