https://de.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2020-04-09T12:02:32Ztag:de.mathworks.com,2005:Question/5166022020-04-09T12:00:42Z2020-04-09T12:02:17ZHow to read text file seperately row by row into different arrayHi, everyone. If the text tile data is shown as below:
13,7,8,4,9
3,21,5,3,7
4,6,87,35,7
45,2,5
I would like to read the text file into different array like a=[13 7 8 4 9], b=[3 21 5 3 7;4 6 87 35 7] and c=[45 2 5]. Is there any code to solve this problem? Thank you for reading my question. Suat Ching Lauhttps://de.mathworks.com/matlabcentral/profile/authors/17721351-suat-ching-lautag:de.mathworks.com,2005:Question/5166032020-04-09T12:01:08Z2020-04-09T12:02:32ZCurious failure of numerical integration: only large values in input array leads to breakdownI have two ways of formulating a joint distribution.
The numerical integration to compute the marginal distribution yields either perfectly equal results or differs by more than 50 orders of magnitude depending on the input.
The problem is demonstrated in the following MWE. Any ideas what is going on?
1. Formulation
jointDistr1 = @(b, a) pdf('Rician', b, a, 1).*lognpdf(a, 0.1, 1);
marginalDistr1 = @(m) integral(@(a) jointDistr1(m, a), 0, inf, 'arrayValued', 1);
2. Formulation
jointDistr2 = @(b, loga) pdf('Rician', b, exp(loga), 1).*normpdf(loga, 0.1, 1);
marginalDistr2 = @(m) integral(@(loga) jointDistr2(m, loga), -700, 700, 'arrayValued', 1);
Integration should be -inf to inf, but too small or too large values yield 0 or inf in the exponential function. -700 and 700 are close to log(realmin) and log(realmax).
marginalDistr1 and marginalDistr2 should yield equal results. For some inputs it works fine:
format long
marginalDistr1([1,5,10,20])
ans = 1×4
0.359729648110231 0.033132531723532 0.003846412255201 0.000310208096516
marginalDistr2([1,5,10,20])
ans = 1×4
0.359729648110231 0.033132531723532 0.003846412255201 0.000310208096516
But if the vector only contains larger values, marginalDistr2 underestimates the result by more than 50 orders of magnitude
marginalDistr1([19,20])
ans = 1×2
10-3 ×
0.379260699103891 0.310208096516368
marginalDistr2([19,20])
ans = 1×2
10-59 ×
0.271279702424388 0.000000010988636
As long as the input contains at least one small value (equal to large output), it works perfectly
marginalDistr1([2,30:35])
ans = 1×7
0.298732142956190 0.000058064954599 0.000050360450307 0.000043832838303 0.000038279111993 0.000033535198445 0.000029467760808
marginalDistr2([2,30:35])
ans = 1×7
0.298732142956191 0.000058064954599 0.000050360450307 0.000043832838303 0.000038279111993 0.000033535198445 0.000029467760808
Reducing the tolerance for numerical integration does not improve the issue (default relative and absolute tolerances are 10^-6 and 10^-10):
marginalDistr2b = @(m) integral(@(loga) jointDistr2(m, loga), -700, 700,...
'arrayValued', 1, 'relTol', 10^(-10), 'absTol', 10^(-15));
marginalDistr2b([19,20])
ans = 1×2
10-59 ×
0.271279702424388 0.000000010988636Ludger Starkehttps://de.mathworks.com/matlabcentral/profile/authors/8269590-ludger-starketag:de.mathworks.com,2005:Question/5163622020-04-08T13:55:15Z2020-04-09T12:00:06Zplotting a 2D-characteristic map with 3rd parameter as linesHello,
Is there a way to create such a plot with Matlab?
There are three variables (distance, voltage, flow rate). The third variable should appear in the form of oblique lines in the 2D plot.
Regards
LisaLanauhttps://de.mathworks.com/matlabcentral/profile/authors/11192200-lanautag:de.mathworks.com,2005:Question/5131622020-03-26T17:19:12Z2020-04-09T11:55:45ZMatlab 2020a installation problem in Linux I’m having problem installing Matlab 2020a on Linux (Pop!_OS 19.10 based on Ubuntu 19.10). I’m getting this error during the installation “Missing File No route to host (Host unreachable)”. Can someone help, pleas?
Roman Konarikhttps://de.mathworks.com/matlabcentral/profile/authors/10325012-roman-konariktag:de.mathworks.com,2005:Question/5165922020-04-09T11:10:57Z2020-04-09T11:51:30ZIterating formula until value converges So the problem is i would like to use a while loop to iterate an equation by substituting values calculated in the last iteration into the next iteration until the value epsilon_conv converges to some small number such as 0.001. Below is the code so far, i am able to find the first iteration ok but then i'm not sure how to sub the new values in and use the equation for epsilon_conv with the old and new beta values to find convergence. Thanks in advance.
clear all;
syms Sy Pa b h Pb l
f=(Sy-(Pa/(b*h)))-(6*Pb*l/(b*h^2)); % master equation
dSy=diff(f,Sy); % f diffirentiated wrt Sy
dPa=diff(f,Pa); % f diffirentiated wrt Pa
db=diff(f,b); % f diffirentiated wrt b
dh=diff(f,h); % f diffirentiated wrt h
dPb=diff(f,Pb); % f diffirentiated wrt Pb
dl=diff(f,l); % f diffirentiated wrt l
Sy=4000; % values used in first iteration
Pa=2500;
b=2;
h=5;
Pb=900;
l=16;
Sys=400; % values used in first iteration
Pas=250;
bs=0.2;
hs=0.5;
Pbs=90;
ls=1.6;
epsilon=1;
epsilon_conv=0.001;
i=1;
while epsilon>epsilon_conv
if i=1
oldbeta=1;
else
DSy=subs(dSy); % Substituting values into diffirentiated equations
DPa=subs(dPa);
Db=subs(db);
Dh=subs(dh);
DPb=subs(dPb);
Dl=subs(dl);
fnorm=subs(f);
beta1=fnorm/sqrt((DSy*Sys)^2+(DPa*Pas)^2+(Db*bs)^2+(Dh*hs)^2+(DPb*Pbs)^2+(Dl*ls)^2); % defining beta
a11=-(DSy*Sys)/sqrt((DSy*Sys)^2+(DPa*Pas)^2+(Db*bs)^2+(Dh*hs)^2+(DPb*Pbs)^2+(Dl*ls)^2);
a21=-(DPa*Pas)/sqrt((DSy*Sys)^2+(DPa*Pas)^2+(Db*bs)^2+(Dh*hs)^2+(DPb*Pbs)^2+(Dl*ls)^2);
a31=-(Db*bs)/sqrt((DSy*Sys)^2+(DPa*Pas)^2+(Db*bs)^2+(Dh*hs)^2+(DPb*Pbs)^2+(Dl*ls)^2);
a41=-(Dh*hs)/sqrt((DSy*Sys)^2+(DPa*Pas)^2+(Db*bs)^2+(Dh*hs)^2+(DPb*Pbs)^2+(Dl*ls)^2);
a51=-(DPb*Pbs)/sqrt((DSy*Sys)^2+(DPa*Pas)^2+(Db*bs)^2+(Dh*hs)^2+(DPb*Pbs)^2+(Dl*ls)^2);
a61=-(Dl*ls)/sqrt((DSy*Sys)^2+(DPa*Pas)^2+(Db*bs)^2+(Dh*hs)^2+(DPb*Pbs)^2+(Dl*ls)^2);
Sy=Sy+(beta1*Sys*a11); %%% new value of Sy etc. to be used in calculation of next iteration
Pa=Pa+(beta1*Pas*a21);
b=b+(beta1*bs*a31);
h=h+(beta1*hs*a41);
Pb=Pb+(beta1*Pbs*a51);
l=l+(beta1*ls*a61);
Sys=(x12-Sy)/Sys; %% new value of Sys etc. to be used in calculation of next iteration
Pas=(x22-Pa)/Pas;
bs=(x32-b)/bs;
hs=(x42-h)/hs;
Pbs=(x52-Pb)/Pbs;
ls=(x62-l)/ls;
epsilon_conv=(oldbeta-newbeta)/newbeta %% number that must converge to 0.001abreg123https://de.mathworks.com/matlabcentral/profile/authors/17032096-abreg123tag:de.mathworks.com,2005:Question/5166012020-04-09T11:51:06Z2020-04-09T12:02:26Z Graph Method Root Finding'X - 2^(-X) = 0'
how can I find the roots of this equation by using graphic method? fplot()Fatih Ayhttps://de.mathworks.com/matlabcentral/profile/authors/18065716-fatih-aytag:de.mathworks.com,2005:Question/5166002020-04-09T11:49:19Z2020-04-09T11:51:00ZPhysics Problem using Matlab ScriptI need help with the problem below. I have no clue how to solve it. I need help as soon as possible. Please help me
Build an algorithm in Matlab, through which you draw the trajectory of a body, thrown from height h0 (given in input), with initial velocity v0x = 10 m / s. After how long does the body reach the ground (tmax)? What is the horizontal displacement of the xmax body? The acceleration of free fall is g = 9.8 m / s2.
Dark Shadowhttps://de.mathworks.com/matlabcentral/profile/authors/18076093-dark-shadowtag:de.mathworks.com,2005:Question/5165342020-04-09T06:31:59Z2020-04-09T11:50:57ZI need help please As soon as you can I try to run this code to solve an n x n linear
system using the Gaussian Elimination Methods
but it says there is error in Error: File: mad.m Line: 7 Column: 20
Illegal use of reserved keyword "for".
can anybody solve the problem and send the code?
for i=j+1:m
a(i,:)=a(i,:)-a(j,:)*(a(i,j)/a(j,j));
enda = input('Enter the augument matrix:');
[m,n]=size(a);
for j=1:m-1
for z=2:m
if a(j,j)==for i=j+1:m
a(i,:)=a(i,:)-a(j,:)*(a(i,j)/a(j,j));
enda = input('Enter the augument matrix:');
[m,n]=size(a);
0;
t=a(j,:);a(j,:)=a(z,:);
a(z,:)=t;
end
end
end
end
end
x=zeros(1,m);
for s=m:-1:1
c=0;
for k=2:m
c=c+a(s,k)*x(k);
end
x(s)=(a(s,n)-c)/a(s,s);
end
disp('Gauss elimination method:');
a;
x';Mahdi Almahuzihttps://de.mathworks.com/matlabcentral/profile/authors/17400849-mahdi-almahuzitag:de.mathworks.com,2005:Question/5156202020-04-05T21:50:41Z2020-04-09T11:48:41ZDisplay mean of data on a boxchartI need to show the mean of each box plot on the figure. here is the code to generate my box plot:
x = 1:numel(data);
colors = rand(numel(data), 3);
figure();
ax = axes();
hold(ax);
for i=1:numel(data)
boxchart(x(i)*ones(size(data{i})), data{i},'MarkerStyle','none', ...
'BoxFaceColor', colors(i,:), ...
'LineWidth', 0.5, ...
'WhiskerLineStyle', '-')
end
set(gca,'xtick',[])
When I had just one boxplot I simply used this line:
hold on
plot(mean(x), '*')
But here when I use it in the code:
x = 1:numel(data);
colors = rand(numel(data), 3);
figure();
ax = axes();
hold(ax);
for i=1:numel(data)
boxchart(x(i)*ones(size(data{i})), data{i},'MarkerStyle','none', ...
'BoxFaceColor', colors(i,:), ...
'LineWidth', 0.5, ...
'WhiskerLineStyle', '-')
plot(mean(data{i}), '*') %%%%%%%%%%<<<<<<<<<<<<< HERE
end
set(gca,'xtick',[])
It shows all mean values on the first boxplot only, meanwhile I need to have one * as a mean value for each boxplot.
Best RegardsBehzad Navidihttps://de.mathworks.com/matlabcentral/profile/authors/15525777-behzad-naviditag:de.mathworks.com,2005:Question/5165992020-04-09T11:47:53Z2020-04-09T11:47:53ZCan not promote requirements in slreq file (requirements written in Req Editor)Hello
I am not able to promote or demote reuiremenys (the button in the toolstrip is blanked). Similarly I am not able to move up or down requirements as when I "right click", the options are blanked (please see snapshot)
I can edit requirements, Cut, Copy Delete etc.
Abhishek Kumarhttps://de.mathworks.com/matlabcentral/profile/authors/11889062-abhishek-kumartag:de.mathworks.com,2005:Question/5136892020-03-29T06:42:19Z2020-04-09T11:47:10Zmcc error with uisetcolor on macos catalinaDear experts,
We noticed a compatibility issue of compiled app on macos catalina (10.15.3). This issue were reproducable in MATLAB 2018a and 2019b.
The color selection funciton "uisetcolor" works well in the MATLAB enviroment.
However, when we compiled this script to an standalone app using mcc, the output of the app goes to blank.
Thank you very much.
Mingrui Xiahttps://de.mathworks.com/matlabcentral/profile/authors/17970291-mingrui-xiatag:de.mathworks.com,2005:Question/5157082020-04-06T09:06:22Z2020-04-09T11:46:49ZVarying Font Size Within individual wordsI need to produce the symbol "FA/FI" on the y-axis label with the "A" and the "I" in a font 3 sizes smaller than each "F". I do not want to use subscripts. In Microsoft Word, one achieves this by clicking on an icon on the toolbox. How does one do it in Matlab?Ben Kormanhttps://de.mathworks.com/matlabcentral/profile/authors/9512021-ben-kormantag:de.mathworks.com,2005:Question/5162982020-04-08T09:59:42Z2020-04-09T11:44:55ZHow to construct the coefficient matrix（Pentagonal matrix） of five-point difference scheme?I want to solve an elliptic partial differential equation.
Step 1: I've the five difference scheme for this equation as follows
.
Then this scheme ends up with a linear system
, where is a coefficient matrix.
Step 2: Construct matrix with Matlab.
The matrix has the following form
So, how to construct the pentagonal matrix? I do not know how to write elements in pentagonal form, please give me some advice.anji yanghttps://de.mathworks.com/matlabcentral/profile/authors/15954724-anji-yangtag:de.mathworks.com,2005:Question/5164352020-04-08T18:09:10Z2020-04-09T11:43:59ZPossible to generate HDL from 5G Toolbox Code?The documentation for the 5G Toolbox makes mention of C/C++ code generation utilizing Matlab Coder. Is it also possible to utilize the HDL Coder in the same fashion to create synthisizable HDL logic?Chris Carrerashttps://de.mathworks.com/matlabcentral/profile/authors/18099708-chris-carrerastag:de.mathworks.com,2005:Question/5030652019-08-19T04:00:00Z2020-04-09T11:43:56ZWhy is half-precision slower than double-precision?While executing same calculations in MATLAB, speed of double-precision variables is faster than half-precision.
Is this normal? Is there any way to speed up?
MathWorks Support Teamhttps://de.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:de.mathworks.com,2005:Question/5165952020-04-09T11:21:06Z2020-04-09T11:42:08ZTrying to create polyval but mine only works for a single value of x , how to make it work for an array?
i am trying to create polyavl but in deed i was only succssufull in creating a function that does polyval work in condition that x is a single value , how can i make my function work wetheir my x is a single value or an array?
my fonction that only works for a single value of x :
function [Y] = polyvalali(A,x)
Y = 0;
value = length(A) - 1;
p = value:-1:0;
for i = 1:value+1
Y = Y + A(i) * x^p(i);
endAli Ramadanhttps://de.mathworks.com/matlabcentral/profile/authors/17352668-ali-ramadantag:de.mathworks.com,2005:Question/5160262020-04-07T12:23:37Z2020-04-09T11:41:51ZAveraging two curves of a graphFor my project I need to find and plot the average of the curves produced by this code, then take their logarithm and plot that. I've tried to use previous answers however I'm completely new to MATLAB and have been struggling a lot, so I was wondering if anyone could please help out?
clear;
t_end=30; % time
a12=0.4; % level of toxicity
a21=0.6;
ht=0.1; % time step size
%inital conditions:
u=0.1;
v=0.5;
nh=t_end/ht;
%--------------------------------------------
t=0; k=0;
U1=zeros(nh,1);
V1=zeros(nh,1);
for j= 1:nh
U1(j)=u;
V1(j)=v;
u0=u+ht*u*(1-u-a12*v);
v0=v+ht*v*(1-v-a21*u);
u=u0;
v=v0;
t=t+ht;
k=k+1;
end;
% Defining the time
E=0:ht:t;
% plotting the profiles
figure
plot(E(2:end),U1,'b',E(2:end),V1,'r');
xlabel('Time')
ylabel('Relative Populations')
legend({'= u','= v'},'Location','southeast')
% Equations to quantify the success of invasions. Alex Totirhttps://de.mathworks.com/matlabcentral/profile/authors/17654051-alex-totirtag:de.mathworks.com,2005:Question/5165982020-04-09T11:41:25Z2020-04-09T11:41:25Z detector = trainFasterRCNNObjectDetector(trainData, layers, options, ... 'NegativeOverlapRange', [0 0.3], ... 'PositiveOverlapRange', [0.6 1], ... 'BoxPyramidScale', 1.2);Error: parallel.gpu.CUDADevice.hBuild
An unexpected error occurred trying to retrieve CUDA device properties. The CUDA error was:
CUDA_ERROR_UNKNOWN
Error: parallel.gpu.GPUDevice.getDevice (line 76)
d = parallel.gpu.CUDADevice.hBuild( idx );
Error: parallel.gpu.GPUDevice.isAvailable (line 146)
device = parallel.gpu.GPUDevice.getDevice( index );
Error: nnet.internal.cnn.util.isGPUCompatible (line 9)
if(iCanUsePCT() && parallel.gpu.GPUDevice.isAvailable())
Error: nnet.internal.cnn.util.GPUShouldBeUsed (line 17)
tf = nnet.internal.cnn.util.isGPUCompatible();
Error: vision.internal.cnn.trainNetwork>iSetupExecutionEnvironment (line 134)
GPUShouldBeUsed = nnet.internal.cnn.util.GPUShouldBeUsed( ...
Error: vision.internal.cnn.trainNetwork (line 43)
executionSettings = iSetupExecutionEnvironment( opts );
Error: fasterRCNNObjectDetector.trainRPN (line 175)
[rpn, info] = vision.internal.cnn.trainNetwork(dispatcher, layers, opts,
checkpointSaver);
Error: trainFasterRCNNObjectDetector (line 289)
[stage1Detector, rpn, info] = fasterRCNNObjectDetector.trainRPN(trainingData, rpn,
options(1), iStageOneParams(params), checkpointSaver);
Error: rcnn_car_object_detection (line 84)
detector = trainFasterRCNNObjectDetector(trainData, layers, options, ...
Le Huanghttps://de.mathworks.com/matlabcentral/profile/authors/18109071-le-huangtag:de.mathworks.com,2005:Question/5150682020-04-03T10:33:16Z2020-04-09T11:37:47ZWhy am I getting compile errors when deploying a matlab function that uses snapshot() from raspberry pi cameraboard together with deep learning?I have two sections in my function. First, it captures an image from the raspberry pi camera module. Deploying it on the hardware as standalone was successful. Then I added another set of code — using AlexNet to classify the captured image. After making the necessary changes in coder.DeepLearningConfig() (a new feature in MATLAB 2020a), this error came up during deployment:
error: cannot convert ‘uint64m_T*’ to ‘uint64_t’ for argument ‘1’ to ‘int EXT_CAMERABOARD_snapshot (uint64_t*, uint8_T8*, uint32_T*)’
.
.
.
recipe for target 'cameraboard.cpp.o' failed
It seems like there was a problem with compiling the cameraboard when using it with deep learning models. To check that there was really no problem with AlexNet, I tried deploying it without the cameraboard and it worked. Are there any fixes for this? Miguel Doradohttps://de.mathworks.com/matlabcentral/profile/authors/16534405-miguel-doradotag:de.mathworks.com,2005:Question/5155182020-04-05T13:03:59Z2020-04-09T11:36:48ZThe input images for activations must be of size equal to or greater than [224 224 3].my code is:
augmentedTrainset=augmentedImageDatastore(imagesize,...
trainset,'ColorPreprocessing','rgb2gray');
augmentedTestset=augmentedImageDatastore(imagesize,...
testset,'ColorPreprocessing','rgb2gray');
featureLayer = 'fc1000';
trainingFeatures = activations(net, augmentedTrainset, featureLayer, ...
'MiniBatchSize', 39, 'OutputAs', 'columns');
[224 224 3] image size
And I take an error as "The input images for activations must be of size equal to or greater than [224 224 3]."
Why I'm taking this error, how can I fix it?aitali hassnahttps://de.mathworks.com/matlabcentral/profile/authors/11053381-aitali-hassnatag:de.mathworks.com,2005:Question/5165362020-04-09T06:45:26Z2020-04-09T11:34:59ZHow can I use parameters from workspace in custom equation using fittype function? I'd like to write the coefficient, in the custom equation, in literal form, keeping A as the solution of the curve fitting
function A = coffin_coefficient(X,Y)
[xData, yData] = prepareCurveData( X, Y );
ft = fittype( 'A*x^(-6.9397)*exp(0.8084/((8.6173e-05)*(120+273.15)))', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Algorithm = 'Levenberg-Marquardt';
opts.Display = 'Off';
opts.StartPoint = 0.1;
Carmelo Barbagallohttps://de.mathworks.com/matlabcentral/profile/authors/15828750-carmelo-barbagallotag:de.mathworks.com,2005:Question/5162962020-04-08T09:57:43Z2020-04-09T11:34:52ZAccessing an element of an array using an array as its index.Hello,
I am writing up an interpolation function and need to define the vertices of the hypercube surrounding the current values.
My current code to do this is:
% (3) Calculate the A values that are the vertices of the N-D hypercube.
a = zeros(1,2^size(CURRENT,1)-1);
curridx = zeros(1,size(CURRENT,1));
idx = zeros(1,size(CURRENT,1));
for cnt = 1:(2^size(CURRENT,1))
change = find((mod(cnt-1,2.^(0:size(CURRENT,1)-1))==0)==1);
curridx(change) = 1*curridx(change)==0;
for cnt1 = 1:size(CURRENT,1)
idx(cnt1) = lidx(cnt1)*(curridx(cnt1)==0)+uidx(cnt1)*(curridx(cnt1)==1);
end
Subs = num2cell(idx);
a(cnt) = DATA(Subs{:});
end
With the profiler showing that the lines
Subs = num2cell(idx);
a(cnt) = DATA(Subs{:});
Are 32.1% and 23.8% of the total run-time respectively. Does anybody know a more efficient method?
Thank you!
Ayden Clayhttps://de.mathworks.com/matlabcentral/profile/authors/13798870-ayden-claytag:de.mathworks.com,2005:Question/5163892020-04-08T15:24:01Z2020-04-09T11:34:46ZStruct to numeric variable Hi,
Sorry but this is a really simple question. I have a struct (3 fields and 446 elements) and I'm trying to access a a specific field and assign it to a workspace variable. I used the following syntax:
new_var = structname.fieldname
However, when I do this, I just get the first row of data in my field name. I want all the rows in structname.fieldname to be assigned to new_var.
When I try structname(1).fieldname or structname(2).fieldname - i get the corresponding row data only. I've tried the following: structname.fieldname(:,1) but get the following error message:
Expected one output from a curly brace or dot indexing expression, but there were 446 results.
Also tried structname(:).fieldname but again, just get the first row of data in fieldname - I'd like all 446 elements.
I know this is very simple but I just can't figure it out!Impalahttps://de.mathworks.com/matlabcentral/profile/authors/8210466-impalatag:de.mathworks.com,2005:Question/5165972020-04-09T11:33:33Z2020-04-09T11:33:33ZSave an image with a plotHey, see if anyone can fix a problem I have. I add an example using the sample image 'cameraman.tif', the image of the real code is another one but to get an idea it works perfectly.
I need to highlight the detected outline, so what I came up with was to get the pixel coordinates and represent them on top of the image by saying that these points are thicker.
Also, I make a crop of the image and I need to show in the original image the crop rectangle used.
When I save it, I want the highlighted pixels to look white and the square to look any other color, for example red.
Do you have any ideas on how to make the image as tight as possible so that the white pixels look white and not black?
Translated with www.DeepL.com/Translator (free version)
I = imread('cameraman.tif');
BW = edge(I,'canny');
[J,rect2] = imcrop(BW);
[r,c] = find ( BW == 1 );
pP = [c r];
f = figure;
imshow(I)
hold on
plot(pP(:,1),pP(:,2),'.w','MarkerSize',5)
rectangle('Position',rect2,'EdgeColor','red','LineWidth',3)
print('TH.tif','-dtiff')
What i want to obtain
What i obtain using print.
Alajendro Fernándezhttps://de.mathworks.com/matlabcentral/profile/authors/14262385-alajendro-fernandeztag:de.mathworks.com,2005:Question/5165842020-04-09T10:30:09Z2020-04-09T11:28:52ZUsing MATLAB’s FFT Command evaluate Discrete Time Fourier Series for x[n] = cos(6πn/17 + π/3)clc;
clear all;
N=17;
n=0:1:5;
x=cos(6*pi*n/N + pi/3)
subplot(2,1,1);
stem(n,x) %Plot discrete function
y= fft(x); %Fourier series function
subplot(2,1,2);
stem(n,real(y));Murali Singhhttps://de.mathworks.com/matlabcentral/profile/authors/17832830-murali-singhtag:de.mathworks.com,2005:Question/5136742020-03-29T03:52:15Z2020-04-09T11:28:24ZMatlab 2020 plot icons missingI recently installed 2020 and the plot tools are not the same.
There used to be an icon on the very right of the toolbar to open figure palette,
plot browser, and property editor. Now I have to click view > figure palette,
then view > plot browser, then view > property editor.
Is there a way to add these icons as before?Zahra Sharifnezhadazizihttps://de.mathworks.com/matlabcentral/profile/authors/8736014-zahra-sharifnezhadazizitag:de.mathworks.com,2005:Question/5163602020-04-08T13:40:36Z2020-04-09T11:27:18ZHow to input excluded dataSo I have recorded behaviours 'Tier_Labels' (e.g. walking, running, sitting) for individual birds (identified by Bird, Pen & Strain). I have aggregated the data to develop a cumulative sum each specific Tier_Label was performed at different habituation times.
%% Aggregation SPSS Function in Matlab
% Creates a table of SUM Total_Duration2 for each Tier Label
G4 = groupsummary(T,{'Bird','Pen','Strain','Habituation','Tier_Labels',},'sum', 'Total_Duration2')
However, some of these behaviours, don't occur for every bird, at every habituation time. I was to create code (potentially a loop) which will say:
For every individual (Bird,Pen,Strain,Habituation),
If 'Behaviours' are missing from the recorded 'Tier_Labels'
Add in a row with that behaviour listed as Total_Duration 0.00
I think a loop is the right way forward but I'm a novice at coding and I'm not sure if there is function that can look at a variable and identify missing labels from a pre-written varibale and then input these into the data set.
Hopefully that makes sense, can anyone help? Or give me some pointers in the right direction?
Thanks :) Justine Pearcehttps://de.mathworks.com/matlabcentral/profile/authors/12544376-justine-pearcetag:de.mathworks.com,2005:Question/5165962020-04-09T11:25:07Z2020-04-09T11:25:07ZProblem reference: 20040912-JH7OM4L9Hi, trying to download the academic version of Matlab & Simulink and after following the link in the email response confirming an academic license it prompts me to sign in. Ive tried resetting my password but still get an error page that says:
SSL connect error
There was a problem displaying this page. This may be a temporary problem, so please try again. If the error persists please contact the system administrator.
Problem reference: 20040912-JH7OM4L9
I have tried every day for the last 4-5 days but still get the same error message. Have an assignment due in about 10 days and I need to use Matlab so need to install the software ASAP. Any help would be great.
Thanks,
TobyToby Daltonhttps://de.mathworks.com/matlabcentral/profile/authors/7052006-toby-daltontag:de.mathworks.com,2005:Question/5165652020-04-09T09:11:56Z2020-04-09T11:23:56ZHow can I read and extract Fill Value from netcdf fileI really thanks someone tell me how can I extract fill value, I used following comment it doesn't work. Thanks in advance.
FillValue = ncreadatt(ncfilename,'PRES','FillValue_');
nc{'PRES'}.FillValue_ = ncfloat(99999); Farshid Daryaborhttps://de.mathworks.com/matlabcentral/profile/authors/7812941-farshid-daryabortag:de.mathworks.com,2005:Question/5165822020-04-09T10:26:23Z2020-04-09T11:23:39ZCan not save an updated uitable with editable columnI am using 2019b and I have an App Designer uitable with editable column. While I change a value it changes on the screen/GUI but not when I save it via a button. How can I solve it?
function saveDataButtonPushed(app, event)
global myData;
filter = {'*.csv'};
[file, path] = uiputfile(filter);
fullFileName = [path file];
writecell(myData,fullFileName,'Delimiter',';')
endLluis Rocahttps://de.mathworks.com/matlabcentral/profile/authors/4250935-lluis-rocatag:de.mathworks.com,2005:Question/5165482020-04-09T07:54:44Z2020-04-09T11:17:26ZUsing fprintf to write to multiple files simultaneouslyI want to write the same text to the screen and in to a file. So I have to double the code:
fprintf('this is some text with numbers: %d, %d', x,y);
fprintf(fid, 'this is some text with numbers: %d, %d', x,y);
Alternatively I can introduce a text string to avoid double code:
str = sprintf('this is some text with numbers: %d, %d', x,y);
fprintf(str);
fprintf(fid, str);
But obviously it does not work to use fprintf to write to mutliple files simultaneously? Would be nice if possible.
fprintf([1 fid],'this is some text with numbers: %d, %d', x,y);Mirkohttps://de.mathworks.com/matlabcentral/profile/authors/5189956-mirkotag:de.mathworks.com,2005:Question/5133152020-03-27T09:44:46Z2020-04-09T11:16:10ZFinding mximum value in text fileGood morning,
I here by attached Ocb_pl.txt text file. Could you please anyone tell me how to search Element Stresses and Strains line in text file and note down all elements and coordinates (1,2) stresses and find out maximum stress and in which element and which coordinates.
Thanks in advance .
RAKESH KUMAR TOTAhttps://de.mathworks.com/matlabcentral/profile/authors/17625888-rakesh-kumar-totatag:de.mathworks.com,2005:Question/5159722020-04-07T08:27:52Z2020-04-09T11:16:09Zfor loops and if statements I have a set of questions based on a task. Basically one of the questions ask to write a function that counts the number of values that have a greater value of 100 and above, in one of the specfic coloumns of a matrix (provided that you input a matrix).
can i double check this code and if so, is there anything i can do to fix the errors i get when i input a matrix, since its not working when i run. Any tips and advice thank you in advance.
Aroi Mehuhttps://de.mathworks.com/matlabcentral/profile/authors/14867602-aroi-mehutag:de.mathworks.com,2005:Question/5165932020-04-09T11:11:08Z2020-04-09T11:13:19ZJacobi method in matlabHi there, I'm at the beginning and I don't know how to work with matrices.
I have a function that receives as a parameter, a matrix in the form of CSR, an iteration vector and a tolerance
My function is of form: function [x] = jacobi_sparse (values, colomn, rowptr, c, tol) %1
I create a function which multiplies a matrix A in the form csr (A) with a vector(x), like this: (y = Ax)
function [y] = csr_multiplication(values, colind, rowptr, x) %2
n = length(x);
y = zeros(n, 1);
for i = 1:n
for j = rowptr(i):rowptr(i+1) - 1
y(i) = y(i) + values(j) * x(colind(j));
end
end
endfunction
The function I want to implement %1, i want to use my %2 to return value of x.
tol - is the tolerance under which iterations stop.
The initial vector with which the solution is approximated is 0
It is something like the Jacobian method, and function %1 need to return x, base on function %2.
Please help me, thanks a lot!steve Brianhttps://de.mathworks.com/matlabcentral/profile/authors/18085931-steve-briantag:de.mathworks.com,2005:Question/5165792020-04-09T10:15:12Z2020-04-09T11:12:23ZExtracting rows of a matrix based on values in a specific columnI'm calculating seasonal temperatures from monthy climate data, and I want to extract rows from a matrix based on 3 values in a specific column that are not in a range.
e.g: values in the column range between 1 and 13, and i want to extract the rows for which this column contains 1, 2, and 12
This code has worked when I've needed to extract a range:
ok_autumn = 9 <= x & x <= 11;
autumn = normals(ok_autumn,:);Alice Hardmanhttps://de.mathworks.com/matlabcentral/profile/authors/18021733-alice-hardmantag:de.mathworks.com,2005:Question/5165942020-04-09T11:11:53Z2020-04-09T11:11:53Znumerical double integral of an expression with vector defined variablesHi everyone,
I have to compute double integral for the expression G over phi and theta in the following code numerically. Does anyone have any idea how it must be done, since it is not easy to use trapz or integral2 because of the definition of the variables!
c = 4.2;
d = 10;
r3 = linspace(c, d, 100);
theta = linspace(-pi/2, pi/2, 100);
theta2 = linspace(-pi/2 ,pi/2, 100);
Phi = linspace(0, 2*pi, 100);
Phi2 = linspace(0, 2*pi, 100);
G = r3.*(sin(theta2).*cos(theta).*cos(phi2-phi) - cos(theta2).*sin(theta)) ./(r3.^2 + c.^2 - 2.*r3.*c.*(sin(theta2).*sin(theta).*cos(phi2-phi)+cos(theta2).*cos(theta))).^3/2 ;
Nimahttps://de.mathworks.com/matlabcentral/profile/authors/13687446-nimatag:de.mathworks.com,2005:Question/5165912020-04-09T11:10:54Z2020-04-09T11:10:54ZPlease help me with the code (Squared Prediction Error)I am trying to plot the figure as shown in the image below. When I run the code I don't get anything. Can someone please tell what I am doing wrong. Where I have taken Enz as R1 and R2.
close all; clear all; clc;
x=[1 -1.2 1];
y=[0.3];
xCalc1=[1 0 1 ];
yCalc1=[0.3];
nm=10;
nnzz=16;
R1=sqrt(sum((xCalc1 - x).^2)/sum(xCalc1).^2);
R2=sqrt(sum((yCalc1 - y).^2)/sum(yCalc1).^2);
N=nm/nnzz;
plot(N,R1);
hold on
plot(N,R2)
Heya :)https://de.mathworks.com/matlabcentral/profile/authors/9179792-heyatag:de.mathworks.com,2005:Question/5142442020-03-31T09:48:04Z2020-04-09T11:06:28ZProtein sequence manipulation for adding elements before or after the sequence.how do i add zeros to both ends or one end (before or after) of a protein sequence?
Example:
a protein sequence is given as 'ITYTDCTESGQDLCLCEGSDVCGKGNKCILGSNGEENQCVTGEGTPKPQSHNDGDFEEIPEEYLQ'
how do i add zeros at the beginning before the first element of the sequence?Dannerick Elishahttps://de.mathworks.com/matlabcentral/profile/authors/16361492-dannerick-elishatag:de.mathworks.com,2005:Question/5165762020-04-09T09:56:50Z2020-04-09T10:58:35ZSolve PDE system with initial conditionsI need to solve
dUi(t,x)/dt+а*dUi(t,x)/dx=f(Ui(t,x),t,x), where i=1,...,4
system of PDE with initial conditions.
I tried pdepe, but it's obligatory to set boundary conditions. I have read about discretization method, but understood nothing.
Maybe there are another ways to solve this system?
Or maybe you will provide some examples for discretization method?Artur Aleksanyanhttps://de.mathworks.com/matlabcentral/profile/authors/10314450-artur-aleksanyantag:de.mathworks.com,2005:Question/5165902020-04-09T10:57:36Z2020-04-09T10:57:36ZSeparating and plotting the individual terms from a fitted two-term gaussian function Hello,
I have plotted my data as a histogram and fitted a two-term gaussian function to it. I would now like to use the information produced from plotting this two-term function to plot each of the terms individually. Is this possible and how would I go about doing this?
This is not my data but I am trying to achieve something like this....
Thank you for any help!
Alice Goldhttps://de.mathworks.com/matlabcentral/profile/authors/17937953-alice-goldtag:de.mathworks.com,2005:Question/5165692020-04-09T09:24:58Z2020-04-09T10:57:20ZLSTM for Event Detection on Time Series / Sequences (Gait Analysis)Hello!
In 3-dimensional Gait Analysis, Human Gait Event Detection is a crucial part. The Gold Standard for this is the ground reaction force (GRF) plate. But often there are only 2-3 GRF plates available and so other events throughout the trial (which are not on the GRF) have to be set manually (there are some algorithms too or autocorrelate events from nexus but in some patient groups this doesnt work very well). But espacially the Foot Off event is often set wrong. This paper is using an LSTM with ALL events set manually to detect events of (unseen) patients.
Now my question is: What if we would only use the GRF events in the LSTM to detect all other events of the trial? Is this even possible?
I have been trying some things with the LSTM but can not really make it work. When i use the classify method at the end i get no events, when i use the predict i get some peaks where an event should be, but only in the middle (where the GRF is) not for other steps.
The input is the whole trial of like 700-1000 data points (of 6 different markers --> 18 x 700/1000 matrix) with 5 events. (The event for the Training data is ONLY set if a GRF plate is hit. But for the Test data is should also be set on all other steps where no GRF plate is)
0 is no event
1 is Left Foot Strike
2 is Left Foot Off
3 ist Right Foot Strike
4 is Right Foot Off
Pleas contact me if someone has an idea or needs more information,
Thanks.Barryhttps://de.mathworks.com/matlabcentral/profile/authors/13617080-barrytag:de.mathworks.com,2005:Question/5165892020-04-09T10:57:00Z2020-04-09T10:57:00Zcan someone solve this?impulse-----> h1 [n] = (0.8)n.u[n] ---------> h2 [n] = (0.3)n.u[n] ------>???
these are my two systems i have to get impulse response of the total system?
clc;
clear all;
h1n=[1,0.8,0.64,0.51,0.4096,0.327,0.262,0.209,0.167];
n= [ 0 1 2 3 4 5 6 7 8 9];
x = [ 1 1 1 1 1 1 1 1 1];
y= conv(h1n,x);
ny= 0: length(y);
subplot(2,1,1);
stem(ny,y);
i tried this code but i am getting error in length of stem
AAYUSH MARUhttps://de.mathworks.com/matlabcentral/profile/authors/17850698-aayush-marutag:de.mathworks.com,2005:Question/5165682020-04-09T09:20:53Z2020-04-09T10:53:12Zcoonecting line closer to next xy coordinates based on distance I have attached my XY coordinates and you can see RED and BLUE marked in the picture attached.
I would like to coonect this lines in the similar way, how it appears in picture attached.
Is there any way to do this , if so , can you please do help me out with example code.SatyaPrakash Guptahttps://de.mathworks.com/matlabcentral/profile/authors/16893253-satyaprakash-guptatag:de.mathworks.com,2005:Question/5165882020-04-09T10:51:51Z2020-04-09T10:51:51ZUse the filter synthesis formula to find the impulse response (i.e. the filter coefficients) of the ideal filterHow to Use the filter synthesis formula to find the impulse response (i.e. the filter coefficients) of an ideal bandstop filterRiya Mhttps://de.mathworks.com/matlabcentral/profile/authors/18058160-riya-mtag:de.mathworks.com,2005:Question/5165872020-04-09T10:51:07Z2020-04-09T10:51:07ZGenetic algorithm for trackingHi all,
I am trying to produce a tracking algorithm using a genetic algorithm.
I am having an issue where the values created just decrease forever, i believe i need to create a better fitness function to achieve my desired goal as my current one is just minimising the value. Below is my current fitness function.
function [X_New] = Fitness_Function_X( X_Correction)
%% Fitness function
global Xfval %Car_Position_Current_X
X_New = ( Xfval + X_Correction) ;
end
Is there a way to change the value the system is matching the result to to calculate the cost function or is there a better way to word my fitness function?Cameron Barberhttps://de.mathworks.com/matlabcentral/profile/authors/18108519-cameron-barbertag:de.mathworks.com,2005:Question/5161822020-04-07T20:48:29Z2020-04-09T10:50:55ZHow to fit a monotonically increasing map to a certain data?Assume that I have data, x,y,z all of them are 1xN double. I want to fit a surface with fit([x,y],z,FitType). I want my surface to increase monotonically in x and y. How can I achive this?
Thanks for any advice in advance.Tokdemir Ibrahim Keremhttps://de.mathworks.com/matlabcentral/profile/authors/11009674-tokdemir-ibrahim-keremtag:de.mathworks.com,2005:Question/5165862020-04-09T10:48:17Z2020-04-09T10:48:17ZTifflib.mexw64 is very slow in Matlab vsn 2019bHello,
Following the purchase of the Matlab 2019b version, reading large .tif files (multi stacks) became terribly slow.
With the 2015b version, the reading was very performant using tifflib.mexw64:
For example, to read a 230 X 230 X 2400 tif file:
Loading stacks ... 95.8333%
Elapsed time is 1.185328 seconds.
Number of frames in stack: 2400
Done...
This is what I get with the 2019b version:
Loading stacks... 95.8333%
Elapsed time is 15.738631 seconds.
Number of frames in stack: 2400
Done...
In version 2019b, tifflib.mexw64 has changed, and is now incorporated in the base version. This was not the case for version 2015b: I had downloaded tifflib.mexw64 from Matlab Exchange.
For version 2019, it is possible to use TIFFStack to read large .tif files, but in fact to manipulate these files afterwards once in Matlab (for example to extract a profile according to the Z direction), it again takes an infinite amount of time, so it is not a viable solution.
What's going on? Is there a solution?
Thank you very much for your help,
Below is the function I use to read tif files:
function [stack, n_frames]=read_tiff_stack(stack_filename)
disp('Loading stack ...')
tic
FileTif=stack_filename;
InfoImage=imfinfo(FileTif);
mImage=InfoImage(1).Width;
nImage=InfoImage(1).Height;
n_frames=length(InfoImage);
stack=zeros(nImage,mImage,n_frames,'uint16');
FileID = tifflib('open',FileTif,'r');
rps = tifflib('getField',FileID,Tiff.TagID.RowsPerStrip);
stack(:,:,1)=double(imread(stack_filename,1));
for i=1:n_frames-1
if ~mod(i,100)
clc;
disp(['Loading stacks ... ',num2str(100*i/n_frames), '%']);
end
tifflib('setDirectory',FileID,i);
% Go through each strip of data.
rps = min(rps,nImage);
for r = 1:rps:nImage
row_inds = r:min(nImage,r+rps-1);
stripNum = tifflib('computeStrip',FileID,r);
stack(row_inds,:,i+1) = tifflib('readEncodedStrip',FileID,stripNum-1);
% imagesc(FinalImage(:,:,i)); axis image ; colormap gray
end
end
tifflib('close',FileID);
toc
disp(['Number of frames in stack: ', num2str(n_frames)])
disp('Done ...')
Dominiquehttps://de.mathworks.com/matlabcentral/profile/authors/4738975-dominiquetag:de.mathworks.com,2005:Question/5029882020-01-31T13:18:43Z2020-04-09T10:44:23ZArguments block syntax not being recognisedI'm trying to use an arguments block for input argument validation in a standalone function. I followed the instructions here, and even tried copying the forwardSpeed example:
function forwardSpeed(a,b,c)
arguments
a double
b char
c SpeedEnum
end
% Function code
disp(class(a)) % Line 9 (where the error is located)
disp(class(b))
disp(class(c))
end
however the editor does not highlight the syntax properly, and when I try to run it, I get the following error:
>>forwardSpeed(1,'a',2)
Error: File: /home/$USER/forwardSpeed.m Line: 9 Column: 5
This statement is not inside any function.
(It follows the END that terminates the definition of the function "forwardSpeed".)
The output for my MATLAB version:
>>version
ans =
'9.6.0.1214997 (R2019a) Update 6'Will Hardimanhttps://de.mathworks.com/matlabcentral/profile/authors/14524513-will-hardimantag:de.mathworks.com,2005:Question/5165852020-04-09T10:44:16Z2020-04-09T10:44:16Zlocation of pixel from minimum and maximum value is in histogramcan you help me, please? I want to know where the location of pixel from minimum and maximum value is in histogram ?Yudawan Hidayathttps://de.mathworks.com/matlabcentral/profile/authors/12736707-yudawan-hidayattag:de.mathworks.com,2005:Question/5153252020-04-04T14:28:41Z2020-04-09T10:36:52ZHow can I call a function inside a class in the command window?I'm new to matlab and I want to call a function contained inside a class in the comand window to run it. The method is not static. How can I do it? Also is there a simpler way to run the function? Also what is obj?
classdef my_class
properties
param
end
methods
function [x,y] = my_function(obj,a,b)
....
end
end
end
Jayhttps://de.mathworks.com/matlabcentral/profile/authors/10173287-jay