matlab draw a line using user input values [closed] - matlab

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 months ago.
Improve this question
I want to draw a line using the inputs for values x1,y1 and x2,y2 from the gui edit text box and plot them on the axes.
function

You are trying to convert the graphics handle itself to a number rather than converting the contents of the uicontrol to a number. To get the value, you'll want to use the 'String' property of the uicontrol instead.
x1 = str2double(get(handles.edit1, 'String'));
You will want to do the same for all user-supplied values.

Related

Dont understand the function of cmd_data(ii) = cell2mat(textscan(char(data{i}(ALL_STRT(ii):(ALL_STRT(ii)+4))),'%f')); at all [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
IND_STRT = 0;
ALL_STRT = IND_STRT:12:510;
cmd_data = zeros(length(ALL_STRT),1); %example: x=zeros(1,21) gives you a 1 by 21 matrix
for ii = 1:length(ALL_STRT) %declare variable ii to run from the row of length
if ~isempty(data{i})
cmd_data(ii) = cell2mat(textscan(char(data{i}(ALL_STRT(ii):(ALL_STRT(ii)+4))),'%f'));
end
end
I need to read the EPS from EnduroSat, however i have difficulty understanding the line cmd_data(ii) = cell2mat(textscan(char(data{i}(ALL_STRT(ii):(ALL_STRT(ii)+4))),'%f'));
Im required to utilised MatLab to code and this particular line have an error and i don't understand why.
Whenever you see a complicated line like this in MATLAB, try to break it up.
% find some indices. These values have been selected by the programmer/data, can't say why.
a=ALL_STRT(ii):(ALL_STRT(ii)+4)
% obtain that articular section of the data
b=data{i}(a)
% convert it to a char data type (characters)
c=char(b)
% scan text, and treat them as float
d=textscan(c,'%f')
% the output is a cell array, we want a matrix instead. Make the cell array into a matrix.
cmd_data(ii) = cell2mat(d)
You can read particularly what each of these do better in their documentation pages, and you can see it work if you put a break-point in the code, and see what each of this parts output when you call it. Learn how to debug, is a very very powerful tool

Matlab - plot data from array of structs [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have an array of structs. Every struct holds a set of data for one single measure. Matlab gives me an error when I try to plot this data.
Expected one output from a curly brace or dot indexing expression, but there were 361 results.
How should I rewrite my plot code?
plot(result.structArray_A(:).nonArrayValue_X, result.structArray_A(:).nonArrayValue_Y);
I have found a solution. Simply writing the following does work, even if the syntax does look odd:
plot([result.structArray_A.nonArrayValue_X], [result.structArray_A.nonArrayValue_Y]);

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 to convert a structuring element to an binary image? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How can you convert a structuring element to an binary image in MATLAB? For example, say I need to convert a square structuring element
se = strel('square',7)
Kindly help me in this matter. I really need a method or algorithm.
Use the getnhood method of the strel class:
NH = se.getnhood()
Returns an array NH as defined by the strel se. NOTE: NH is a binary (logical) image (matrix). You can display it as is or you can pad it as suggested by Jigg.
For future reference, you can use tab command completion to see the available methods for a class (hit TAB after typing se.), or you can use methods(se) to get a full list of available methods.
Technically, the array given by chappjc's code is a binary image.
Try displaying it like that:
nh = se.getnhood();
p=padarray(nh, [10 10], 0, 'both'); % This pads the array with zeros
imshow(p);

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