https://de.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2021-03-06T12:09:05Ztag:de.mathworks.com,2005:Question/7647212021-03-06T11:26:55Z2021-03-06T12:09:05ZConcatenate matrices not the same size - without NaNHello,
I am trying to concatenate several matrixes having different sizes (rows and columns).
In order to have the same number of rows and columns so they can be concatenated, I want all the non-existant values of the smaller matrices to fill up with a constant value, so that in the end, all matrices have the same dimensions, which are the greatest number of lines among all matrices by the greatest number of columns among the matrices.
So, to sum up: I have, for example, two matrices A = [1 2 3; 4 5 6; 7 8 9] and B = [1 2; 3 4], and I want a 3D-matrix C = [1 2 3; 4 5 6; 7 8 9] and [1 2 a; 3 4 a; a a a] (with 'a' a given constant).
I tried to do this with the fillmissing function, but it seems it only works when there are NaN in the matrices? Here my matrices are images so the pixels I want to add don't exist at all.
Is there an existing function for this, or do I have to do it "manually"?
Thank you!
NicolasNicolashttps://de.mathworks.com/matlabcentral/profile/authors/8971460tag:de.mathworks.com,2005:Question/7647462021-03-06T12:07:01Z2021-03-06T12:07:01ZTrying to rotate a 32x32x32 matrix for full symmetry group (group theory)Hi all,
I currently have a 32x32x32 matrix and I'm trying to get all possible rotations of it (the full symmetry set) and store them all.
My code is shown below;
It takes a dataset as matrix and then rotates it in 7 different ways around the x axis, this gives me 8 out of the 24 rotations of the full set. Are there functions that do the same as what I did below for the other 2 axes (y and z)? I cannot find a function that does this, and am hesitant to remap everything manually since there's a dataset of 800.000 matrices that I have to do this with.
matrix = dataset(:,:,:,i);
matrix2=flip(matrix);
matrix3=flip(matrix,2);
matrix5=rot90(matrix);
matrix4=rot90(matrix,2);
matrix7=rot90(matrix,3);
matrix6=rot90(flip(matrix));
matrix8=rot90(flip(matrix),3);Simon Penninaghttps://de.mathworks.com/matlabcentral/profile/authors/11478634tag:de.mathworks.com,2005:Question/3958952018-04-18T19:44:13Z2021-03-06T12:06:09ZHow can I get a loop to process all ".avi" files in a folder, then produce the corresponding ".txt" and ".png" file?I am creating a deep learning CNN with Python and Tensorflow, but the information that will be used in the network will be processed in MATLAB, and so my task is as follows:
I am to use MathWorks' sample code for MotionBasedMultiObjectTracking, but modify it in such a way that as it tracks a moving object, such as a person, in a supplied '.avi' file, it retrieves the (x,y) coordinates of the centroid of the bounding box as it moves in each frame, and writes that information to a '.txt' file. While it does this, it should also print a pattern of white dots onto an all black image, which represents the centroid/(x,y) coordinates as they change across each frame, and save the resulting image as a '.png' file.
I already have this part but that information was supplied just to provide a better understanding of what I'm trying to accomplish overall. Now my problem is that I can't figure out how to write a function or script that can go through all of my .avi files and produce the corresponding x,y coord .txt file and dot pattern .png file. Here is some code:
function MotionBasedMultiObjectTrackingExample()
% create a white image
imageTraj = 255 * ones(480, 640, 'uint8');
blackTraj = 0 * imageTraj;
% create a file to save trajectory data
fileID = fopen('Pattern 1-1.txt','w+');
%imshow(image);
% Create System objects used for reading video, detecting moving objects,
% and displaying the results.
obj = setupSystemObjects();
tracks = initializeTracks(); % Create an empty array of tracks.
nextId = 1; % ID of the next track
% Detect moving objects, and track them across video frames.
while ~isDone(obj.reader)
frame = readFrame();
[centroids, bboxes, mask] = detectObjects(frame);
predictNewLocationsOfTracks();
[assignments, unassignedTracks, unassignedDetections] = ...
detectionToTrackAssignment();
updateAssignedTracks();
updateUnassignedTracks();
deleteLostTracks();
createNewTracks();
displayTrackingResults();
end % end of while
fclose(fileID);
saveas(gcf,'Pattern 1-1.png');
%open the generated image for dilation
BW = imread('Pattern 1-1.png')
%dilation function(strel('dilation type', dilation_strength))
SE = strel('square', 8);
%actually perform the dilation and show the new dilation image
BW2 = imdilate(BW,SE);
figure,imshow(BW2), title('Dilated')
%resize the dilated image
BW3 = imresize(BW2, [64 64]);
figure, imshow(BW3), title('Resized and dilated')
saveas(BW3,'resizedBW3.png');
%% Create System Objects
% Create System objects used for reading the video frames, detecting
% foreground objects, and displaying results.
function obj = setupSystemObjects()
% Initialize Video I/O
% Create objects for reading a video from a file, drawing the tracked
% objects in each frame, and playing the video.
% Create a video file reader.
%obj.reader = vision.VideoFileReader('udcvideo.mp4.mp4');
obj.reader = vision.VideoFileReader('Scenario 1-1.avi');
% Create two video players, one to display the video,
% and one to display the foreground mask.
obj.maskPlayer = vision.VideoPlayer('Position', [740, 400, 700, 400]);
obj.videoPlayer = vision.VideoPlayer('Position', [20, 400, 700, 400]);
% Create System objects for foreground detection and blob analysis
% The foreground detector is used to segment moving objects from
% the background. It outputs a binary mask, where the pixel value
% of 1 corresponds to the foreground and the value of 0 corresponds
% to the background.
obj.detector = vision.ForegroundDetector('NumGaussians', 3, ...
'NumTrainingFrames', 40, 'MinimumBackgroundRatio', 0.7);
% Connected groups of foreground pixels are likely to correspond to moving
% objects. The blob analysis System object is used to find such groups
% (called 'blobs' or 'connected components'), and compute their
% characteristics, such as area, centroid, and the bounding box.
obj.blobAnalyser = vision.BlobAnalysis('BoundingBoxOutputPort', true, ...
'AreaOutputPort', true, 'CentroidOutputPort', true, ...
'MinimumBlobArea', 400);
end % end of setupSystemObjects()
My videos are named in the folder as follows: Scenario 1-1 to 1-10, Scenario 2-1 to 2-10.... Scenario 10-1 to 10-10. So there's 100 '.avi' files in the folder. In the setupSystemObjects() function, I supply the video file reader with 'Scenario 1-1.avi'. When I run the program, it runs the process on Scenario 1-1.avi, produces Pattern 1-1.txt, and Pattern 1-1.png, just like I want. The big question is how can I loop it, updating the file name each time so that every time the function is called, it will move to the next file, let's say 'Scenario 1-2.avi' for example, and produce the respective .txt and .png files, all the way until it has finished with the 100 videos in the folder.
I have developed this loop but I'm not sure how to proceed from here: (The comments on the inside below 'code would go here' was just me trying different things.
function FileExample()
d = uigetdir('','Select Input-folder'); %select the input-folder that contains the subfolders
cd(d);
list = dir;
list = list([list.isdir]);
list = list(~ismember({list.name},{'.' '..'}));
l=length(list);
for i=1:l
oldfolder = cd(list(i).name);
% Perform your operation on the files, e.g., if you are working with avi files
files = dir('*.avi');
numberOfFiles = length(files);
for k = 1:numberOfFiles
% code would go here
%
% file name files(k)
% MotionBasedMultiObjectTrackingExample( files(k) )
end
cd(oldfolder);
end
endTevin Galeshttps://de.mathworks.com/matlabcentral/profile/authors/12419132tag:de.mathworks.com,2005:Question/7645912021-03-06T08:46:54Z2021-03-06T11:56:46ZLatex text in Y-AxisHi,
I am trying to add text and D_i to y-axis, but it gives error. Could you please help?
xlabelname = sprintf('Number of Samples','${D_{i}}$' );
xlabel(xlabelname, 'fontsize', 30, 'interpreter', 'latex')
thanks in advance!Brave Ahttps://de.mathworks.com/matlabcentral/profile/authors/14350471tag:de.mathworks.com,2005:Question/7647412021-03-06T11:54:31Z2021-03-06T11:54:31ZCan't navigate to code in Simulink CoderGood day to you,
I've been following a tutorial for the Requirements and Simulink Coder perspectives ( https://it.mathworks.com/videos/verification-validation-and-testing-in-simulink-1550691741461.html?elqsid=1595582526479&potential_use=Education ) but I seem to be unable to follow it to the letter. I am using Matlab 2020b and whenever I click on the Generate and Build Model from the Simulink Coder perspective, the System returns an incomplete report compared to the one in the video, missing Static Code Metrics Report and several other options. Additionally, though the code seems to have been created by the Coder, I can't seem to locate either a "Code" tab from the Coder perspective (which should be next to Properties), nor can I find the "Navigate To Code" option from the Requirements perspective. Am I missing some addons? Or is it an issue with newer versions of Matlab?Marco Montanarohttps://de.mathworks.com/matlabcentral/profile/authors/14974441tag:de.mathworks.com,2005:Question/7559142021-02-25T12:45:55Z2021-03-06T11:54:30ZExcursion of loudspeaker model is drifting massivlyHello everyone,
for a project that I am working on I need a nonlinear loudspeaker model( currently only the Force and Suspension) so I made one in Simulink. While Parameters like SPL and Distortion look fine, the cone excursion suffers from a massive offset drift in both the linear and nonlinear version of the Model:
While I expect some offset with it beeing nonlinear and all, 2.5 Meters seem quite excessive... here is the Schematic:
I am at a loss as to where this comes from. Has anybody an Idea what could cause this? I attached the .slx of the Speaker if annybody needs it. I already tried different solvers to no avail.
Have a nice day and thanks for anny pointers or Help.Christian Noackhttps://de.mathworks.com/matlabcentral/profile/authors/9004965tag:de.mathworks.com,2005:Question/7636012021-03-05T06:34:27Z2021-03-06T11:53:03ZCan anybody help me to implement caughey's equivalent linearization method for bilinear structure in MATLAB? I am not able to get the ductility(x/x0) vs frequency ratio(w/ws) plot.These are some images from "Passive control of bilinear hysteretic structures by tuned mass damper
for narrow band seismic motions" Z. Zhang, T. Balendra.
VAIBHAV PUJARIhttps://de.mathworks.com/matlabcentral/profile/authors/17179308tag:de.mathworks.com,2005:Question/7646162021-03-06T09:21:44Z2021-03-06T11:52:28ZHow do you import specific rows of numeric data (without text) for the file I have attached?Hi, how can I import the numeric data for each location (there are tables for 6 locations) in the file I have attached? I want to import rows 6-11, 14-45, 58-89 and 91-122 etc (all the arrays separately basically). I would really appreciate if anyone could provide an example code. Thank you in advance.Tahiru Gunasekerahttps://de.mathworks.com/matlabcentral/profile/authors/11195887tag:de.mathworks.com,2005:Question/7647062021-03-06T11:25:58Z2021-03-06T11:44:40ZTest Post Welcome YouHi This is TESThehe hehehttps://de.mathworks.com/matlabcentral/profile/authors/21762918tag:de.mathworks.com,2005:Question/7381472021-02-07T02:16:09Z2021-03-06T11:41:22ZHow to apply a Farrow structure delay filter(FIR) to a signal in Matlab? For a signal, which is very common, just like this one
t=linspace(0,100e-6,1024);
k=10e13;
y=exp(-1i*k*pi*t.^2);
The function in the signal processing toolbox of MATLAB is used to generate a delay filter with Farrow structure, and the filter coefficients are obtained.
L=18;
d = fdesign.fracdelay(abs(Delay),'N',L);
farrow = design(d, 'lagrange', 'FilterStructure', 'farrowfd');
farrow_coff=farrow.Coefficients;
Is it because the previous delay filter is not correct, the function filter can not correctly filter to obtain the desired results?
Or please give me a simulation example for reference.chen jiyuanhttps://de.mathworks.com/matlabcentral/profile/authors/18687023tag:de.mathworks.com,2005:Question/7647362021-03-06T11:41:21Z2021-03-06T11:41:21ZIntegration using quad helpCan anyone explain why I am having an error
"Error in quad (line 67)
y = f(x, varargin{:});"???
I am trying to integrate e^(x)/((10*x)-1) with limits 0 to 200
y1 = quad('((exp.^(x)./((10.*x)-1)))',0,200)Ashis Pandeyhttps://de.mathworks.com/matlabcentral/profile/authors/21436925tag:de.mathworks.com,2005:Question/7606062021-03-02T16:20:56Z2021-03-06T11:38:36ZConnection Error when installing add onWhen I click "Sign in to Install", it shows this. I read the support article, turned off the anti-virus, tried adding the environment variables, changed networks, but still shows this.
Nandha Shreehttps://de.mathworks.com/matlabcentral/profile/authors/17220636tag:de.mathworks.com,2005:Question/7647312021-03-06T11:38:08Z2021-03-06T11:38:08ZButterworth Bandpass Filter DesignWhy [b,a] = butter(n,Wn,'bandpass') designs a Butterworth filter of order 2n?
How to design an odd-order Butterworth filter with this command? Kam Shahttps://de.mathworks.com/matlabcentral/profile/authors/11625001tag:de.mathworks.com,2005:Question/7647262021-03-06T11:36:44Z2021-03-06T11:36:44ZHow to find intersection between lines I have below code
%% Input Values
clear all
clc
alpha1=input('Enter positive "alpha1"?');
alpha2=input('Enter positive "alpha2"?');
beta1=input('Enter positive "beta1"?');
beta2=input('Enter positive "beta2"?');
lambda=input('Enter positive "lambda"?');
eta1=input('Enter positive "eta1"?');
eta2=input('Enter positive "eta2"?');
P=input('Enter positive "P"?');
%% Feasible Area
x = -1:P;m = 0; c = eta2; y = m * x + c;
plot(x, y, 'black')
y = -1:P; m = 0; c = eta1; y = m * x + c;
plot(y, x, 'black')
eta1=min (eta1,P); eta2=min (eta2,P);
if eta1==0 && eta2==0;
X=[0 0 P]; Y=[0 P 0];
fill(X,Y,[0.85 0.85 0.85]); axis([-1 P -1 P])
end
if eta1+eta2<P
X=[0 0 eta1 eta1]; Y=[0 eta2 eta2 0];
fill(X,Y,[0.85 0.85 0.85]);
else
X=[0 0 P-eta2 eta1 eta1]; Y=[0 eta2 eta2 P-eta1 0];
fill(X,Y,[0.85 0.85 0.85]); axis([-1 P -1 P])
end
X=[0 0]; Y=[0 P];
line(X,Y,'Color','black')
hold on
line(Y,X,'Color','black')
g = @(x,y) x+y-P;
y1=fimplicit(g,[0 P 0 P])
f = @(x,y) log((1+alpha1*x./(1+alpha2*y))) -lambda*log((1+beta1*x./(1+beta2*y)));
y2=fimplicit(f,[-1 P -1 P], '-')
hold on
grid on
Where I consider alpha1=1, alpha2=0.2, beta1=1; beta2=2, lambda=2, eta1=2, eta2=3, P=1
I want to find the intersection for lines in the picture. Could you please help me!
Hossein Alishahihttps://de.mathworks.com/matlabcentral/profile/authors/12960900tag:de.mathworks.com,2005:Question/7617762021-03-03T15:11:42Z2021-03-06T11:34:08ZHow can i filter the spectrogram colours and take as matrix?Hello, I am trying to change spectrogram matrix colours. I am writing audio and music recognition system based on Spectrogram.
function spectrogram_graph(audiofile_name)
[y,fs]=audioread(audiofile_name);
fprintf("Amount of Fs is:%d \n",fs)
specgram(y);
xlabel("Samples")
ylabel("Normalized Frequency (x pi radians/sample)")
colormap gray
c=colorbar;
c.Label.String="Powerfrequency dB(rad/sample)";
end
I have this table from this function:
I need to filter, for example: Higher than -40dB will be white and lowers will be black. I need to recieve this as matrix with only ones and zeros. Thats why i am using grayscale.
Firsty, I couldnt filter and change the colours of the spectrogram.
Secondly, I couldnt obtain 2D matrix of the spectrogram.
Can you help me please guys, best wishes
AltemurAltemur Çelikayarhttps://de.mathworks.com/matlabcentral/profile/authors/16453584tag:de.mathworks.com,2005:Question/7646612021-03-06T10:24:58Z2021-03-06T11:31:50Zfsolve terminate far before finding answer when using TolFun optionfsolve terminate far before finding answer when using TolFun option. I wrote a simple code to show my problem:
======================================
clc
clear
Opt=optimoptions('fsolve','Tolfun',1);
x0=10;
x_solution=fsolve(@fff,x0,Opt);
function y=fff(x)
y=x;
end
=========================
x_solution=6.5
6.5^2=42.5 and is far from (Tolfun=1)
Can anyone help me to know how should I solve this issue. Thanks a lothosein bashihttps://de.mathworks.com/matlabcentral/profile/authors/13222538tag:de.mathworks.com,2005:Question/7647162021-03-06T11:26:44Z2021-03-06T11:26:44ZMatrix factorization with respect to symbolic variableI have a square symbolic matrix that I wish to decompose in powers of the symbolic variable. For example A is the symbolic matrix :
A = [3*x^2 2i ; 3i x+5]
I want to decompose it in this form :
A=x^2* [3 0 ;0 0] + x*[0 0 ;0 1] +[0 2i ; 3i 5]
Unfortunately the functions I found take only polynomials as inputs ,not matrices . Any help would be greatly appreciated !Mark R.https://de.mathworks.com/matlabcentral/profile/authors/20485626tag:de.mathworks.com,2005:Question/7647112021-03-06T11:26:01Z2021-03-06T11:26:01ZIsolate clusters from a series of pointsI have a set of points whose x and y coordinates are stored into two vectors.
imshow(Imm)
hold on
plot(Lpix_x,Lpix_y,'go')
Plotting the vector on a image I obtain this result
I want to plot only the clusters of points circled in red, deleting the other points.
How can I do that?
Thank you Federicahttps://de.mathworks.com/matlabcentral/profile/authors/11007789tag:de.mathworks.com,2005:Question/7647012021-03-06T11:22:56Z2021-03-06T11:22:56ZHOW CAN I SOLVE THIS?Ting Yu Leehttps://de.mathworks.com/matlabcentral/profile/authors/21613199tag:de.mathworks.com,2005:Question/7641462021-03-05T17:19:31Z2021-03-06T11:21:57ZQuestion regarding app designer - incrementing values based on button click, and row namesHi folks,
Firstly, I'm trying to add row names to my table in the app designer. Despite having named them in the inspector, the names don't appear even when running the app.
Secondly, is there a way to intialise the table values to zero, then increment individual cells based on a button click?
I've attached an image of the mock-up below.
Thanks in advance!
Teshan Rezelhttps://de.mathworks.com/matlabcentral/profile/authors/17128181tag:de.mathworks.com,2005:Question/7646962021-03-06T11:18:50Z2021-03-06T11:18:50ZImage Registration Satellite Landsat-8I'm struggling with finding a way to make an image registration... I have LANDSAT-8.tif images but I don't know how and from where to start coding in order to align images. Do you have some advises?Marco Laterzahttps://de.mathworks.com/matlabcentral/profile/authors/19989412tag:de.mathworks.com,2005:Question/7646912021-03-06T11:17:10Z2021-03-06T11:17:10ZCreating a table with matrices and arrays as elementsHi, Hope you're safe and fine.
My question is how to create a table whose elements are not necessarily of the same rows. For instance, I have attached a built-in table from "Monocular Visual Odometry" example of MATLAB. In this table, the first element is a number, the second one is a 1x3 vector of location, and the thrid one is a 3x3 matrix of rotation.
Any ideas are appreciated!Mohammad Hussein Yoosefianhttps://de.mathworks.com/matlabcentral/profile/authors/9905478tag:de.mathworks.com,2005:Question/7641962021-03-05T18:14:01Z2021-03-06T11:16:29ZSymsum function for basic electrical engineering calculations. I am trying to write a symsum function so that i can calculate different basic Electrical engineering functions with Integrals (Average,effective value and equivalency)
I have this piece of code wich is built for a cos/sin funktion and im trying to change it so that i can also build a sum function (symsum) to make it do the same calculations. As a example I am trying to simulate this signal:
with
für = for ,and, sonst = otherwise
with T = 10ms, u0 = -2 and u1 = 10,
I wrote this Code based on another code and I want to build this to fit the u(t) function. It might be that the Uav, Uaav and Ueff wont work with the u(t) i want to build, but that is another problem. My main problem is that I cant make the variabel u working so that I can get the signal. I wouldnt really need the -inf to the inf only a period(like 0 - 10ms per period) (for the later functions Uav,Uaav,Ueff) but that doenst really change my problem as the symsum function doesnt seem to work.
clear all;
close all;
u0 = -2; % Volt
u1 = 10; % Volt
T = 0.001; %10ms
tmin = 0;
tmax = T;
N = 100;
t = linspace(tmin,tmax);
t1 = transpose(t);
It didnt accept t and so i used t1 to transpose it.
s = [tmin,tmax];
n = log(0);
k = log(0);
F = sum(s.*(t1-(n.*T)),k,n,Inf);
u = (u0+u1)*F;
The " s.*(t1-(n.*T)) " really seems to be the troubling part and I tried different things but I cant solve it. I also think that the variable F is a bit Fishy.
Uav = trapz(t,u)/T;
Uaav = trapz(t,abs(u))/T;
Ueff = sqrt(trapz(t,u.^2)/T);
disp(["Mittelwert: ",num2str(Uav)," Volt"]);
disp(["Gleichrichtwert: ",num2str(Uaav)," Volt"]);
disp(["Effektivwert: ",num2str(Ueff)," Volt"]);
plot(t*1000,u,"r");
grid on;
xlabel("t/ms");
ylabel("u(t)/V");
A friend of mine also suggested to build a "for" loop but I think the symsum function would give me what I need.
I solved the problem on paper already but I cant get it to transfer it onto a matlab code. Samuel the Helplesshttps://de.mathworks.com/matlabcentral/profile/authors/16553250tag:de.mathworks.com,2005:Question/7646862021-03-06T11:13:20Z2021-03-06T11:13:20Znum2str formatI have problems with num2str format
I get a number from an API:
8.1784e+17
I need the exact number as str output. For instance I know it is:
'817835078876192769'.
I tried with:
num2str(x,'%u')
however this gives me the following wrong result:
ans =
'817835078876192768'
Anyone have a clue what can be wrong here?Martinhttps://de.mathworks.com/matlabcentral/profile/authors/4265483tag:de.mathworks.com,2005:Question/7646762021-03-06T11:06:42Z2021-03-06T11:12:07ZMatlab standalone exe closes after calling another Malab exe from itI am calling one exe from command propmt. It has one command line which calls another Matlab standalone application. These two applications need to communicate to each other via a .mat file. But, just after the first exe calls second exe, first exe is closing on it's own ( observed in Taskmanager). Even i have tried removing all clear statements from the seond exe. I am using memorymap for the ,mat file to share the data between the two applications. I do not understand the problem behind it. I don,t have parallel computing toolbox.
Calling of second exe from Matlab is running without any difficulty. Even i Have tried running the scripts in two different Matlab sessins which were running without any problem.
I am using ! Trial_memap_Mod1.exe & command to call second exe from the first.
Any suggestions would be of great help.Manishhttps://de.mathworks.com/matlabcentral/profile/authors/2226091tag:de.mathworks.com,2005:Question/7642212021-03-05T18:41:16Z2021-03-06T11:04:19ZHow can I record mouse clicks (left and right) with coordinates and time? Hello,
I am trying to capture mouse movements outside of the GUI, on second display while users are using another program. So far, I manage to record the coordinates, every 0.1 seconds period, by using timer function. I need to add mouse clicks (left or right button down and ups). Does anyone know how can I do this? I try to Buttondownfnc but it only works with a figures not outside of the Matlab..or is there any workaround?
fileID = fopen('motion.txt','wt');
t = timer('ExecutionMode', 'fixedRate','Period', 0.1, 'TasksToExecute', 200, ...
'TimerFcn', @(~,~) fprintf(fileID,'(X, Y) = (%g, %g)\n', get(0, 'PointerLocation')));
start(t);Doli Sweyhttps://de.mathworks.com/matlabcentral/profile/authors/19536320tag:de.mathworks.com,2005:Question/7646712021-03-06T11:01:41Z2021-03-06T11:01:41ZConvoluting simulated image with real detector MTFHi everyone,
I would like to include the effect of the detector response on transmission electron microscope images I am simulating. In principle, I understand that the simulated image has to be convolved with the detector modulation transfer function. To practically attain this I would have to firstly FFT the image and then multiply it by the MTF. After this I would have to perform an iFFT of the result to get an image in real space which has the MTF influence.
I am struggling to understand how I can convolve a 2D image with a 1D detector MTF.
Examples of the MTF and images I am simulating are attached.Arthur Moyahttps://de.mathworks.com/matlabcentral/profile/authors/8498922tag:de.mathworks.com,2005:Question/7646662021-03-06T10:59:07Z2021-03-06T10:59:07ZGenerate cell of random numbers with same size arraysHello!
I'd like to generate a 3x2 cell, whose arrays are all matrixes 5x100 of random numbers.
I am a bit struggling with it, depsite I think is quite easy to do.
Any suggestion?
ThanksRiccardo Zabattahttps://de.mathworks.com/matlabcentral/profile/authors/16761799tag:de.mathworks.com,2005:Question/7646512021-03-06T10:24:31Z2021-03-06T10:51:51ZWriting a structure to a txt fileI have a structure which contains some parameters for a function:
F1Parameters.adaptedThresholdValue = 0.38;
F1Parameters.BWopenValue = 800;
F1Parameters.seDiskValue = 32;
I want to be able to write this to a text file in the following format, which keeps the structure name as the first column.
Function Parameter Value
F1_Parameters adaptedThresholdValue 0.38
F1_Parameters BWopenValue 800
F1_Parameters seDiskValue 32
To do this, I'm using the code below, but this seems like a very inefficient way to do it - am I missing an obvious way of just exporting the structure with the structure name as the first column?
% write F1 parameters to a txt file
table_F1Parameters = struct2table(F1Parameters); % convert F1 parameters to table
transposed_F1Parameters = rows2vars(table_F1Parameters); % transpose table
column_F1 = (repelem("F1_Parameters",height(transposed_F1Parameters)))'; % create new column to label F1, repeat name of structure
column_F1 = array2table(column_F1); % convert new column to table
final_F1_table = [column_F1,transposed_F1Parameters]; % concatenate column and table
final_F1_table.Properties.VariableNames = ["Function","Parameter","Value"]; % rename headers
writetable(final_F1_table,sprintf("%s",myFolderOutput,"Parameters"),"Delimiter","tab"); % write table to txt fileBChttps://de.mathworks.com/matlabcentral/profile/authors/17076341tag:de.mathworks.com,2005:Question/7646562021-03-06T10:24:52Z2021-03-06T10:43:36Zdeblurring an image with deconvwnrI am trying to deblur a motion-blur with deconvwnr , but the results is very poor
hers is the code :
% %first step: motion blurring
Len = 20; % linear motion of the camera given in pxels
Theta = 135; %angle of the motion given in conter-clockwise direction
h = fspecial('motion',Len,Theta);
f_blurred = imfilter(f,h,'conv','replicate');
% using deconvwnr for deblurring :
NSR = 0; %no noise
deblurred = deconvwnr(f_blurred,h,0);
the below image is the result, as you see it is extremely corrupted, why is that ?
when I changed the noise-parameter slightly it became a bit more visible, but still poor. My image is only blurred, no noise, shouldnt wiener work much better with this simple type of motion blur?
Her is the original image :
Eirik Kvernevikhttps://de.mathworks.com/matlabcentral/profile/authors/21364707tag:de.mathworks.com,2005:Question/7644562021-03-06T02:50:39Z2021-03-06T10:34:56ZUsing If for symsHi,
I hope you are keeping safe.
I have a urgent question in matlab. Could you please give me sime advice in this regard. I wrote following code where
"function F = fun(x,y,alpha1,alpha2,beta1,beta2,lambda)
F= log((1+alpha1*x./(1+alpha2*y))) -lambda*log((1+beta1*x./(1+beta2*y)));
end"
Main Code
Z=fun(x,P-x,alpha1,alpha2,beta1,beta2,lambda);
z=solve(Z==0);
for i=1:length(z)
z(i,1)=piecewise(z(i,1)<=0,0)
y(i)=P-z(i,1)
S(i)=fun(z(i,1),y(i),alpha1,alpha2,beta1,beta2,lambda)
end
I want to z(i,1)=0 if z(i,1)<=0 or complex and if z(i,1)>0, claculate S(i) but there is a problem with piecewise() which cannot be solved for me.
Could you please help me to write it. P, alpha1, alpha2, beta1, beta2, and lambda are desired positive valuse.
Many Thanks in advance.Hossein Alishahihttps://de.mathworks.com/matlabcentral/profile/authors/12960900tag:de.mathworks.com,2005:Question/7646462021-03-06T10:04:29Z2021-03-06T10:26:52ZDelete empty cells in array; keep column / row structureI have a 17x31 cell array (A) with empty cells. I need to delete all empty cells and reduce the array accordingly. I.e. in the example screenshot the output should be a 17x2 array.
With the following code I get a single column (34x1):
newA = A(~cellfun(@isempty, A));
Any ideas?
Jamackerhttps://de.mathworks.com/matlabcentral/profile/authors/8483759tag:de.mathworks.com,2005:Question/7646412021-03-06T09:54:12Z2021-03-06T10:25:06ZUnrecognized function or variable in app designerI would like to run a Matlab script from an App, but i get the error "unrecognized funtion or variable simduration".
In the app, I use 2 buttons. One for assigning values to the base workspace and one to run the script "zwembad_model_app".
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: runsimulationButton
function runsimulationButtonPushed(app, event)
%simout = sim("test_app","StopTime",num2str(app.DurationEditField.Value));
zwembad_model_app
plot(app.UIAxes,simout.watertemperatuur.Time,simout.watertemperatuur.Data);
end
% Button pushed function: SaveParametersButton
function SaveParametersButtonPushed(app, event)
assignin("base","simduration",app.DurationEditField.Value);
assignin("base","lengte",app.lengteEditField.Value);
assignin("base","breedte",app.breedteEditField.Value);
assignin("base","diepte",app.diepteEditField.Value);
assignin("base","start_temperatuur",app.starttemperatuurEditField.Value);
assignin("base","U_bodem",app.U_bodemEditField.Value);
assignin("base","U_wand",app.U_wandEditField.Value);
assignin("base","U_cover",app.U_coverEditField.Value);
assignin("base","opticalefficiency",app.opticalefficiencyEditField.Value);
assignin("base","a1",app.heatlosscoefficientlinearEditField.Value);
assignin("base","a2",app.heatlosscoefficientquadraticEditField.Value);
assignin("base","Ac",app.collectorsurfaceEditField.Value);
assignin("base","serie",app.serieEditField.Value);
assignin("base","parallel_test",app.parallelEditField.Value);
assignin("base","min_temperature_gain",app.mintemperaturegainEditField.Value);
end
end
This is the code from the matlab script (I'm aware that this line of code can be simply integrated in the app code and that works fine but later on I want to expand the script).
simout = sim("test_app","StopTime",num2str(simduration));
When running the app I can see the variables getting stored in de base workspace when the Saveparameters button is activated, but when I press the runsimulation button I get the error. When running the script seperately (after pressing saveparamters button in the app), there is no problem.
I'm not experienced in working with app designer so I hope there is some simple solution I overlooked.
Any help will be appreciated!
Yari Van Heckehttps://de.mathworks.com/matlabcentral/profile/authors/16419290tag:de.mathworks.com,2005:Question/593162013-01-20T06:10:12Z2021-03-06T10:17:08ZUsing fzero with multiple parametersHaving trouble debugging error...
I have 2 scripts:
-function
-script that calls function for use
I'm pasting both scripts along with the error I received and where exactly I think the problem is (according to the error).
*Function*:
function F=EXPLICITFUNCTION(x)
F = x(1) + x(2) + x(3) - T2;
x(1)*exp(m*L) + x(2)*exp(-m*L) + x(3) - T1;
-k*(x(1)*m*exp(m*L)-x(2)*m*exp(m*L)) + k*(m*(x(1)-x(2))) - x(4);
P*h*((x(1)*(exp(L*m) - 1))/m - (x(2)*(1/exp(L*m) - 1))/m) - x(4);
end
*Script*:
%______________________________
clear all
clc
%______________________________
T2 = 375; %........................K
T1 = 450; %........................K
D = 0.003; %........................m
P = pi*D; %........................m
A_Cond = (pi/4)*(0.003-0.002); %.........m^2
h = 257.799; %......................W/(m^2*K)
k = 70; %......................W/(m*K)
L = 0.03; %......................m
m = sqrt((h*P)/(k*A_Cond)); %.......(1/m)
x0= [15;12;450;12];
fzero(@(x) MMAE322SUPERFUNCTION(x, T2, T1, m, L, k, P, h), x0)
The error I receive is:
-Error using fzero (line 413)
Second argument must be a scalar or vector of length 2.
-Error in MMAE322SCRIPT (line 19)
fzero(@(x) MMAE322SUPERFUNCTION(x, T2, T1, m, L, k, P, h), x0)
Somehow I think it's because of my guess, x0. I need 4 guesses, one for each unknown variable, but I don't know how to interpret the error. I tried for the sake of debugging by erasing 2 guess in my x0 and of course that didn't work..
I've done this before with a single parameter and single guess but anymore than 1 parameter I get a similar error.
Any help is greatly appreciated! :)Davehttps://de.mathworks.com/matlabcentral/profile/authors/3996595tag:de.mathworks.com,2005:Question/7646212021-03-06T09:31:02Z2021-03-06T10:13:45ZHow to Speedup conditional vector elements replacement? Dear,
a is a vector its values correspond to the number of times to repeat the
corresponding number drawn from the vector b. following this rule the result
is a vector c.
as an example:
a=[1 4 1 4 4 1];
b=[1 6 8 3 9 2];
c=[1 6 6 6 6 8 3 3 3 3 9 9 9 9 2]
Is there any vectorization solution for this proplem?
RegardsOmar Ali Muhammedhttps://de.mathworks.com/matlabcentral/profile/authors/17769638tag:de.mathworks.com,2005:Question/932972010-01-27T23:56:00Z2021-03-06T09:59:18ZWhy does the MathWorks installer fail to start on Windows?I am trying to install MATLAB on a Windows computer, but the installer will not run.MathWorks Support Teamhttps://de.mathworks.com/matlabcentral/profile/authors/4622813tag:de.mathworks.com,2005:Question/7646362021-03-06T09:53:01Z2021-03-06T09:53:01Za problem with task15.2 (4/6) of MATLAB fundamental courseHallo
I am doing matlab fundamental course, and reached the "Creating and calling functions" section (4/6)
I have two problems : first, I was asked to provide a seconf input for the function , getLargestN(x) so it becomes : getLargestN(x,5) for example. however, whenver I wrote down the second input : 5 or 7 or whatever, I get an error message .so in task 1, I ignored the second input , but still got a corret answer and moved on to the next task 2.
it is essentially the same asa task one, just to have an output of the top 7 numbers instead of 5. so easy so far. and I actually got the right results ofcourse on the workspace. yet on the right hand side panel where the test results appear : I got an x , a false next to the question : does the function evaluate correctly? (please see attached screen shot) although it is actually evaluating right, and despite the fact that I replicated task 1 exactly.
please see this :
https://snipboard.io/il4YF3.jpg
so what to do in this case?
thank you in advance
Haya Alamlehhttps://de.mathworks.com/matlabcentral/profile/authors/18353813tag:de.mathworks.com,2005:Question/4824812019-09-27T14:05:05Z2021-03-06T09:51:52ZConverting equation to matlabHi, I am trying to convert the following equation to matlab code. I have a bunch of defined constants above this code but I am trying to figure out if my formatting is correct since I keep getting the wrong answer. I need to multiply the two functions and they are dependant on the variable E, everything else is a constant. Thanks!
Christos Papedohttps://de.mathworks.com/matlabcentral/profile/authors/16362458tag:de.mathworks.com,2005:Question/7645862021-03-06T08:39:17Z2021-03-06T09:48:13ZHow Can speed up "for" loop ?Hi,
How can I speed up following 'for' loops? Help me please.Thanks.
N=1000 > 30sec , N=1000 > 10min , N=100000 > 5hr up can't produce result
N = 100000;
B= 0.3;
Pf=linspace(0.9,0.1,n);
data = randi([0,1],N, 1);
for k=1:2
Lambda= (1+sqrt(2/N)*qfuncinv(Pf))*var(wgn(N, 1,0) .* sqrt(p(k)/2));
for i = 1:length(Pf)
Nd_BPSK=0;
for j=1:N
noise_BPSK = wgn(N, 1,0) .* sqrt(p(k)/2);
h_BPSK = raylrnd(B, N, 1);
receive_BPSK = abs(h_BPSK).*send_BPSK + noise_BPSK;
T_simu_BPSK(i)=sum(abs(receive_BPSK).^2)/N;
if T_simu_BPSK(i) > Lambda(i)
Nd_BPSK=Nd_BPSK+1;
end
end
Pd_simu_BPSK(i,k)=Nd_BPSK/j;
end
for i = 1:length(Pf)
Nd_QPSK=0;
for j=1:N
noise_QPSK = wgn(N/2, 2, 0) .* sqrt(p(k)/2);
h_QPSK = raylrnd(B, N/2, 2);
receive_QPSK = abs(h_QPSK).*send_QPSK + noise_QPSK;
receive_QPSK2=reshape(receive_QPSK,N,1);
T_simu_QPSK(i)=sum(abs(receive_QPSK2).^2)/N;
if T_simu_QPSK(i) > Lambda(i)
Nd_QPSK=Nd_QPSK+1;
end
end
Pd_simu_QPSK(i,k)=Nd_QPSK/j;
end
endNYYminhttps://de.mathworks.com/matlabcentral/profile/authors/17813948tag:de.mathworks.com,2005:Question/7645962021-03-06T08:48:06Z2021-03-06T09:37:19ZNo values for RK methodI have tried to solve a set of coupled first order differential using RK method. However, there is nothing being plotted on my graph. After checking all my codes and values, I still cannot understand where have I go wrong. Would really appreciate if someone is able to look into it.
clear all, clc
%Constants
pg=2.41;
Fgo=1.247;
Fso=4.8;
vgo=0.739;
Cgo=24.446;
Fsup=0.4/0.6*Fso;
Tgo=723;
d=0.5;
A=pi*(d^2)/4;
pb=2200;
ps=(pb)*0.4/160;
ko=1.31*(10^8);
Ea=219900;
R=8.314;
n=0.681;
b=4;
dp=75*(10^-6);
Ap=pi*(dp^2);
Vp=(pi/6)*(dp^3); %Vol. of particle m3
pp=4000; %Particle density kg/m3
Sm=(pb*Ap)/(pp*Vp); %Heat transfer per unit vol. m2/m3
vbar=0.0003; %Superficial gas velocity m/s
%Heat of reaction J/mol
%HOR=(5034082686347630884407*Ts)/22517998136852480000 - 766695369022715765625/(140737488355328*Ts) + (64148441052234189*Ts^2)/1125899906842624000 - (82760967131826871*Ts^3)/6755399441055744000000 + (134900196956432657181*Ts^4)/112589990684262400000000000000 + 31193507971733846684869577643645007001/362427180012640665600000000000000;
%Differential Eq
%dXgdz=(A*ps*k*(Cg^n))/(b*Fgo);
% =(A*ps*(ko*exp(-Ea/(R*Ts)))*(((Cgo*(1-Xg)*Tgo)/((1+(2*Xg))*Tg))^n))/(b*Fgo);
%dXsdz=-A*ps*k*(Cg^n)/Fso;
% =-A*ps*(ko*exp(-Ea/(R*Ts)))*(((Cgo*(1-Xg)*Tgo)/((1+(2*Xg))*Tg))^n))/Fso;
%dTgdz=(A*Sm*h*(Ts-Tg))/(Fgo*(CpM+Xg*(2*CpW+CpC+CpM)));
% =(A*Sm*(((-0.007215+(8.015*(10^-5))*Tg+(5.477*10^-9)*Tg^2+(-1.053*10^-11)*Tg^3)/dp)*0.33*((dp*vbar*pg/((0.002545+(4.549*(10^-5))*Tg+(-8.649*(10^-9))*(Tg^2))))^(1/3)))*(Ts-Tg))/(Fgo*(CpM+Xg*(2*CpW+CpC+CpM)));
%dTsdz=((A*Sm*h*(Ts-Tg))+(Fgo*dXgdz*HOR))/(Fgo*(CpFE2+Xs*(2*CpFE-CpFE2))+Fsup*Cpsup);
% =((A*Sm*(((-0.007215+(8.015*(10^-5))*Tg+(5.477*10^-9)*Tg^2+(-1.053*10^-11)*Tg^3)/dp)*0.33*((dp*vbar*pg/((0.002545+(4.549*(10^-5))*Tg+(-8.649*(10^-9))*(Tg^2))))^(1/3)))*(Ts-Tg))+(Fgo*fXg*HOR))/(Fgo*(CpFE2+Xs*(2*CpFE-CpFE2))+Fsup*Cpsup);
%RK method
fXg=@(z,Ts,Xg,Tg) (A*ps*(ko*exp(-Ea/(R*Ts)))*(((Cgo*(1-Xg)*Tgo)/((1+(2*Xg))*Tg))^n))/(b*Fgo);
fXs=@(z,Ts,Xg,Tg) -(A*ps*(ko*exp(-Ea/(R*Ts)))*(((Cgo*(1-Xg)*Tgo)/((1+(2*Xg))*Tg))^n))/Fso;
fTg=@(z,Ts,Xg,Tg) (A*Sm*(((-0.007215+(8.015*(10^-5))*Tg+(5.477*10^-9)*Tg^2+(-1.053*10^-11)*Tg^3)/dp)*0.33*((dp*vbar*pg/((0.002545+(4.549*(10^-5))*Tg+(-8.649*(10^-9))*(Tg^2))/1000))^(1/3)))*(Ts-Tg))/(Fgo*((36.154+(-0.05111)*Tg+(2.214*(10^-4))*(Tg^2)+(-1.8243*(10^-7))*(Tg^3)+(4.898*(10^-11))*(Tg^4))+Xg*(2*(33.763+(-5.945*(10^-3))*Tg+(2.235*(10^-5))*(Tg^2)+(-9.962*(10^-9))*(Tg^3)+(1.097*(10^-12))*(Tg^4))+(29.268+(-0.02236)*Tg+(2.652*(10^-4))*(Tg^2)+(-4.153*(10^-7))*(Tg^3)+(2.005*(10^-10))*(Tg^4))+(36.154+(-0.05111)*Tg+(2.214*(10^-4))*(Tg^2)+(-1.8243*(10^-7))*(Tg^3)+(4.898*(10^-11))*(Tg^4)))));
fTs=@(z,Ts,Tg,Xs,Xg) ((A*Sm*(((-0.007215+(8.015*(10^-5))*Tg+(5.477*10^-9)*Tg^2+(-1.053*10^-11)*Tg^3)/dp)*0.33*((dp*vbar*pg/((0.002545+(4.549*(10^-5))*Tg+(-8.649*(10^-9))*(Tg^2))/1000))^(1/3)))*(Ts-Tg))+(Fgo*(A*ps*(ko*exp(-Ea/(R*Ts)))*(((Cgo*(1-Xg)*Tgo)/((1+(2*Xg))*Tg))^n))/(b*Fgo)*((5034082686347630884407*Ts)/22517998136852480000 - 766695369022715765625/(140737488355328*Ts) + (64148441052234189*Ts^2)/1125899906842624000 - (82760967131826871*Ts^3)/6755399441055744000000 + (134900196956432657181*Ts^4)/112589990684262400000000000000 + 31193507971733846684869577643645007001/362427180012640665600000000000000)))/(Fgo*((110.9362+(32.04714*(Ts/1000))+(-9.192333*(Ts/1000)^2)+(0.901506*(Ts/1000)^3)+(5.433677/(Ts/1000)^2))+Xs*(2*(45.7512+(18.78553*(Ts/1000))+(-5.952201*(Ts/1000)^2)+(0.852779*(Ts/1000)^3)+(-0.081265/(Ts/1000)^2))-(110.9362+(32.04714*(Ts/1000))+(-9.192333*(Ts/1000)^2)+(0.901506*(Ts/1000)^3)+(5.433677/(Ts/1000)^2))))+Fsup*(146.5551+(35.91295*(Ts/1000))+(-0.183978*(Ts/1000)^2)+(0.031409*(Ts/1000)^3)+(-3.659941/(Ts/1000)^2)));
%Initial conditions
z(1)=0;
Xg(1)=0;
Xs(1)=1;
Tg(1)=723;
Ts(1)=1173;
%Step size
ss=0.0001;
zfinal=1;
N=ceil(zfinal/ss);
%Update loop
for i=1:N
%Update length
z(i+1)=z(i)+ss;
%Update variables
k1Xg=fXg(z(i) ,Ts(i) ,Xg(i) ,Tg(i));
k1Xs=fXs(z(i) ,Ts(i) ,Xg(i) ,Tg(i));
k1Tg=fTg(z(i) ,Ts(i) ,Xg(i) ,Tg(i));
k1Ts=fTs(z(i) ,Ts(i) ,Xg(i) ,Tg(i) ,Xs(i)) ;
k2Xg=fXg(z(i)+ss/2,Ts(i)+ss/2*k1Ts,Xg(i)+ss/2*k1Xg,Tg(i)+ss/2*k1Tg) ;
k2Xs=fXs(z(i)+ss/2,Ts(i)+ss/2*k1Ts,Xg(i)+ss/2*k1Xg,Tg(i)+ss/2*k1Tg) ;
k2Tg=fTg(z(i)+ss/2,Ts(i)+ss/2*k1Ts,Xg(i)+ss/2*k1Xg,Tg(i)+ss/2*k1Tg) ;
k2Ts=fTs(z(i)+ss/2,Ts(i)+ss/2*k1Ts,Xg(i)+ss/2*k1Xg,Tg(i)+ss/2*k1Tg,Xs(i)+ss/2*k1Xs);
k3Xg=fXg(z(i)+ss/2,Ts(i)+ss/2*k2Ts,Xg(i)+ss/2*k2Xg,Tg(i)+ss/2*k2Tg) ;
k3Xs=fXs(z(i)+ss/2,Ts(i)+ss/2*k2Ts,Xg(i)+ss/2*k2Xg,Tg(i)+ss/2*k2Tg) ;
k3Tg=fTg(z(i)+ss/2,Ts(i)+ss/2*k2Ts,Xg(i)+ss/2*k2Xg,Tg(i)+ss/2*k2Tg) ;
k3Ts=fTs(z(i)+ss/2,Ts(i)+ss/2*k2Ts,Xg(i)+ss/2*k2Xg,Tg(i)+ss/2*k2Tg,Xs(i)+ss/2*k2Xs);
k4Xg=fXg(z(i)+ss ,Ts(i)+ss *k3Ts,Xg(i)+ss *k3Xg,Tg(i)+ss *k3Tg) ;
k4Xs=fXs(z(i)+ss ,Ts(i)+ss *k3Ts,Xg(i)+ss *k3Xg,Tg(i)+ss *k3Tg) ;
k4Tg=fTg(z(i)+ss ,Ts(i)+ss *k3Ts,Xg(i)+ss *k3Xg,Tg(i)+ss *k3Tg) ;
k4Ts=fTs(z(i)+ss ,Ts(i)+ss *k3Ts,Xg(i)+ss *k3Xg,Tg(i)+ss *k3Tg,Xs(i)+ss *k3Xs);
Xg(i+1)=Xg(i)+ss/6*(k1Xg + 2*k2Xg + k2Xg*k3Xg + k4Xg);
Xs(i+1)=Xs(i)+ss/6*(k1Xs + 2*k2Xs + k2Xs*k3Xs + k4Xs);
Tg(i+1)=Tg(i)+ss/6*(k1Tg + 2*k2Tg + k2Tg*k3Xg + k4Tg);
Ts(i+1)=Ts(i)+ss/6*(k1Ts + 2*k2Ts + k2Ts*k3Ts + k4Ts);
end
%Plot the solution
figure (1); clf(1)
hold on
plot(z,Xg,'-r','displayname','Xg')
plot(z,Xs,'-b','displayname','Xs')
legend;
ylabel('conversion');
xlabel('Length/m');
hold off
figure (2); clf(2)
hold on
plot(z,Tg,'-r','displayname','Tg')
plot(z,Ts,'-b','displayname','Ts')
legend;
ylabel('Temperature');
xlabel('Length/m');
hold off
Lee Ek Haohttps://de.mathworks.com/matlabcentral/profile/authors/13425444tag:de.mathworks.com,2005:Question/7645612021-03-06T08:07:31Z2021-03-06T09:21:07Zhow to plot graph from text data as shown in the imagesanjiv kumarhttps://de.mathworks.com/matlabcentral/profile/authors/13264122tag:de.mathworks.com,2005:Question/4675022019-06-17T15:59:20Z2021-03-06T09:11:32ZPhased Array Systems ToolboxHi ,
I have some raw data from FMCW radar in .bin format and the I would like to analyse them with "Phase Array system Toolbox" to plot rang angle plot. but when I am running the code thre is the error!
Error using phased.RangeAngleResponse/plotResponse (line 571)
X must be a matrix and must be non-empty.
Error in test (line 158)
plotResponse(rngangresp,radarSource,'Unit','db');
But X isn't empty, could you please help me to solve the problem?
B.R.Sevda Abadpourhttps://de.mathworks.com/matlabcentral/profile/authors/12654924tag:de.mathworks.com,2005:Question/7644312021-03-06T01:45:54Z2021-03-06T09:11:01ZHow to detect a thick grid in an imageI need to determine the lattice constant in pixels and the angle with respect to the axes of the thick grid in a lot of images like the one below.
So i want to plot lines like in the image below and get the distance between two lines and the angle with respect to the axes.
This is my first try at image processing and my first idea was using fourier transformation because of the periodicity of the grid.
Without fully understanding how fourier works in 2D, i tried fft2() and filtered out frequencies with low amplitudes
%create image
I=imread('image','jpg');
I2= im2bw(I,0.2);
BW=-(I2-1);%invert image
%fourier
A=fft2(BW);
ma=max(abs(A),[],'all');
A(abs(A)<0.3*ma)=0;%remove small intensities
imagesc(ifft2(A))
Sadly after inverse fft for the frequencies with the highest amplitudes, the angles are always a little bit off.
The yellow lines are the invese fourier transformation of the frequency with the highest amplitude. As you can see the the yellow lines dont quite match the grid.
I alternativly tried to use hough() alongside edge(), but i only managed to properly detect thin lines this way.
I would be thankful for suggestions of better methods or corrections for the methods i used.Can Kahrimanhttps://de.mathworks.com/matlabcentral/profile/authors/16380937tag:de.mathworks.com,2005:Question/900012013-10-12T12:58:57Z2021-03-06T09:07:51ZHow to plot phase and amplitude spectrum after doing fourier transform?Hello, I am a new MATLAB user. I had a function which I did Fourier Transform for, and the result was: X(w)=1/(1+jw) where w is the frequency and " j " is the known imaginary number. I would like to know what code I should input in MATLAB in order to plot the phase and amplitude spectra of X(w). Thanks in advance...Bilalhttps://de.mathworks.com/matlabcentral/profile/authors/4695644tag:de.mathworks.com,2005:Question/7646112021-03-06T09:04:18Z2021-03-06T09:04:18ZODE 45 step size changes the turning pointI face a problem in ODE 45 that when ever i change my step size which is zspan = [0:0.1:1] in this case, the turning point of the graph changes according to it. If i set my step size at 0.1, the turning point occur at 0.1; step size at 0.5, the turning point occur at 0.5.
It makes me feel like the result that i get is very "rigged" according to the step size indicated.
Is there any way to solve this problem?
function F = Val(z,S)
%A-Fe2O3,B-CH4,C-FeO,D-CO2,E-H2O
Xsf=S(1);
Xgf=S(2);
Tsf=S(3);
Tgf=S(4);
%Explicit Information
%Mass balance parameter in fuel reactor
R=8.314; %Gas constant-J/(mol.K)
d=0.5; %fuel reactor diameter-m
A=(pi*0.25^2); %Cross-sectional area-m2
pg=0.2411; %gas density-kg/m3
vch4=0.0628; %Vol. flow rate of methane-m3/s
Mwch4=16; %Molecular weight of methane-g/mol
Fgof=1.247; %Initial molar flow rate of fuel(methane)-mol/s
pbulk=2200; %Bulk density of reactive material in reactor-kg/m3
ps=2.81; %Molar bulk density of reactive material-mol/m3
kof=1.31*(10^8); %Pre-exponential factor
Ea=219900; %Activation energy-J/mol
Cgof=Fgof/vch4; %Initial concentration of fuel(methane)-mol/m3
Tgof=723; %Initial temperature of fuel(methane)-K
n=0.681; %Order of reaction
Fsof=3; %Initial Fe2O3 feed rate-mol/s
kf=kof*exp(-Ea/(R*Tsf));
Cgf=(Cgof*(1-Xgf)*(Tgof))/((1+(2*Xgf))*Tgf);
%Energy balance parameter of fuel reactor
pparticle=4000; %Density of oxygen carrier-kg/m3
dp=75*(10^-6); %mean particle diameter-m
Ap=pi*(dp^2); %Surface area of a particle-m2
Vp=(pi*(dp^3))/6; %Volume of particle-m3
Sm=(pbulk*Ap)/(pparticle*Vp);
Vbar=vch4/A; %Superficial gas velocity-m/s
mug=(0.001596+((3.439*10^-5)*Tgf)+((-8.14*10^-9)*Tgf^2))/1000; %gas viscosity-kg/(m.s)
Nre=(dp*Vbar*pg)/mug;
kg=(-23.35+(0.1698*Tgf)+((1.893*10^-5)*Tgf^2))*(10^-3); %thermal conductivity of gas-W/(m.K)
h=(0.33*(Nre^(1/3))*kg)/dp;
Fsup=0.5; %Molar flow rate of support material-mol/s
CpA=110.9362+(32.04714*(Tsf/1000))+(-9.192333*(Tsf/1000)^2)+(0.901506*(Tsf/1000)^3)+(5.433677/(Tsf/1000)^2); %Heat capacity of Fe2O3-J/(mol.K)
CpB=-0.703029+(108.4773*(Tgf/1000))+(-42.52157*(Tgf/1000)^2)+(5.862788*(Tgf/1000)^3)+(0.678565/(Tgf/1000)^2); %Heat capacity of CH4-J/(mol.K)
CpC=45.7512+(18.78553*(Tsf/1000))+(-5.952201*(Tsf/1000)^2)+(0.852779*(Tsf/1000)^3)+(-0.081265/(Tsf/1000)^2); %Heat capacity of FeO-J/(mol.K)
CpD=24.99735+(55.18696*(Tgf/1000))+(-33.69137*(Tgf/1000)^2)+(7.948387*(Tgf/1000)^3)+(-0.136638/(Tgf/1000)^2); %Heat capacity of CO2-J/(mol.K)
CpE=30.092+(6.832514*(Tgf/1000))+(6.793435*(Tgf/1000)^2)+(-2.53448*(Tgf/1000)^3)+(0.082139/(Tgf/1000)^2); %Heat capacity of H2O-J/(mol.K)
CpF=146.5551+(35.91295*(Tsf/1000))+(-0.183978*(Tsf/1000)^2)+(0.031409*(Tsf/1000)^3)+(-3.659941/(Tsf/1000)^2); %Heat capacity of Support material-J/(mol.K)
HOR1=360642; %Heat of reaction in fuel reactor-J/mol
%Differential Equation
dXgfdz=(ps*A*kf*(Cgf^n))/(4*Fgof);
dXsfdz=(-ps*A*kf*(Cgf^n))/Fsof;
dTgfdz=(A*(Sm*h*(Tsf-Tgf)))/(Fgof*(CpB+Xgf*(2*CpE+CpD+CpB)));
dTsfdz=(A*(Sm*h*(Tsf-Tgf)+((Fgof/A)*(dXgfdz)*HOR1)))/((Fgof*(CpA+(Xsf*(2*CpC-CpA))))+Fsup*CpF);
F=[dXgfdz; dXsfdz; dTgfdz; dTsfdz];
end
To call out the function file:
XsfO = 0.9;
XgfO = 0;
TsfO = 800;
TgfO = 773;
SO = [XsfO XgfO TsfO TgfO];
zspan = [0:0.1:1];
[z,S] = ode45(@val,zspan,SO);
% Plots
figure(1)
hold on
plot(z,(S(:,1)),'-r','displayname','Xsf')
plot(z,(S(:,2)),'-b','displayname','Xgf')
legend;
ylabel('conversion');
xlabel('Length/m');
hold off
figure(2)
hold on
plot(z,(S(:,3)),'-g','displayname','Tsf')
plot(z,(S(:,4)),'-c','displayname','Tgf')
legend;
ylabel('Temperature(K)');
xlabel('Length/m');
hold offXie Yingjiehttps://de.mathworks.com/matlabcentral/profile/authors/13305200tag:de.mathworks.com,2005:Question/4947742019-12-04T09:47:25Z2021-03-06T08:58:16ZPlots - Two Y-Axis with Different UnitsI need to plot a lot of data from an Excel file. I would like to plot one column of data (flow rate) against the left y-axis and have two columns of data (pressure drops) against the right y-axis. How do I do this?
I thought I could work it out using the help pages, but I have no idea how to code the data. I am importing it from Excel and plotting instead. At the moment the plot looks ridiculous because it is plotting it all against the left y-axis and the values for the pressure drops are small compared to the flow rate. Tony Rankinhttps://de.mathworks.com/matlabcentral/profile/authors/14767101tag:de.mathworks.com,2005:Question/7639312021-03-05T13:13:22Z2021-03-06T08:53:10ZHow to generate multiple random combinations of word pairs with specific restrictions on avoiding repetition?I want to randomly combine word pairs such that I can generate an instruction - e.g., "Spin yellow rubber".
Actions={'spin',
'pick up',
'push',
'touch',
'shake',};
Objects={'yellow rubber',
'white rubber',
'pink ruler',
'blue ruler',
'orange folder',
'green folder',
'purple bag',
'brown bag',
'gold box',
'black box',
'red pencil',
'grey pencil'};
2. I'd like to expand this to generate a sequence of 4 instructions - e.g., "spin yellow rubber, pick up pink ruler, push orange folder, touch gold box'. I want to generate 192 sets of four-sequence instructions [192 x 4].
3. I don't want repetitions of the action AND the object within the sequence of 4 instructions. In my 192 x 4 instructions, I do not want the instruction (e.g., spin yellow rubber) to appear in two consecutive rows.Abi Fiskehttps://de.mathworks.com/matlabcentral/profile/authors/16661776tag:de.mathworks.com,2005:Question/7622762021-03-03T23:15:53Z2021-03-06T08:52:48ZUsing RL, How to train multi-agents such that each agent will navigate from its initial position to goal position avoiding collisions?Let's assume there are a set of agents that are spread into 3d cartesian space. A trajectory should be generated for each agent such that if an agent would follow its trajectory while heading to the goal waypoint, no collision would happen with other agents. Any guidance to solve such a task would be highly appreciatedSteve Jessyhttps://de.mathworks.com/matlabcentral/profile/authors/21728277tag:de.mathworks.com,2005:Question/2469272015-10-05T18:38:06Z2021-03-06T08:44:18Zcan anyone please suggest me how to tackle this problemYour current working folder is:
C:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin
Simulink does not permit you to modify the MATLAB installation area.
Please change to a working folder that is not in the MATLAB
installation area and re-try the previous command.
Component: Simulink | Category: Model errorAMIT VISHWAKARMAhttps://de.mathworks.com/matlabcentral/profile/authors/6972985tag:de.mathworks.com,2005:Question/7645812021-03-06T08:32:25Z2021-03-06T08:32:25Zunable to get the exact waveform in R2020b version for the below codeclc;
clear all;
close all;
M=4;
nsym=512;
nsub=64;
nfft=64;
rand('state',0);
d=randi([0,M-1],nsub,nsym);
%%%%%%d=randint(nsub,nsym,[0 M-1]);
%----------------------------------
tx=qammod(d,M);
%----------------------------------
x=ifft(tx,nfft);
meanSquareValue1=sum(x.*conj(x),2)/nsym;
peakValue1 = max(x.*conj(x),[],2);
paprSymbol1 = peakValue1./meanSquareValue1;
p0 = 10*log10(paprSymbol1);
[cx0,cy0]=ccdf(p0,0.5);
figure,
semilogy(smooth(cy0),smooth(cx0),'k-*');hold on
%%%%% PROPOSED METHOD %%%%%%%%%%%%%%%%%%%%%%5
cl={'r-*','b-*','g-*'};
Ai=max(mean(abs(x)));
sig=max(std(x));
k=0.5;
Pset=[4 4.5 5];
for i=1:length(Pset)
Ac=sig*(10^(Pset(i)/20));
for ii=1:nsub
for jj=1:nsym
if abs(x(ii,jj))<=Ai
y(ii,jj)=x(ii,jj);
elseif abs(x(ii,jj))>Ac
y(ii,jj)=((k.*x(ii,jj))+(1-k).*Ac);
else
y(ii,jj)=sign(x(ii,jj)).*Ac ;
end
end
end
meanSquareValue2=sum(y.*conj(y),2)/nsym;
peakValue2 = max(y.*conj(y),[],2);
paprSymbol2 = peakValue2./meanSquareValue2;
p2 = 10*log10(paprSymbol2);
[cx2,cy2]=ccdf(p2,0.5);
grid on
semilogy((cy2),(cx2),cl{i});hold on
ylim([10^-1.3 10^0]);
xlabel('PAPR(dB)');
ylabel('CCDF');
end
legend('original','Pset-4 dB','Pset-4.5 dB','Pset-5 dB')
title('CCDFs of original OFDM signal and companded signals')
Preethi Chiluveruhttps://de.mathworks.com/matlabcentral/profile/authors/18917021