https://de.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2020-10-26T02:50:44Ztag:de.mathworks.com,2005:Question/6234482020-10-23T04:19:39Z2020-10-26T02:50:44ZHow to draw a 3D circle that is tangent to two linesHi,
May I ask that, I have two 3D lines on the same plane, and I have two known point on the individual line. the angle between two lines is unknown. And now I want to draw a circle that is tangent to both of the lines (on the same plane), and intersect the two known points. Is there a way to do this in matlab. Really appreciated for the help.
Thank you.MingCheng Zhanghttps://de.mathworks.com/matlabcentral/profile/authors/12413009tag:de.mathworks.com,2005:Question/6221332020-10-22T01:37:55Z2020-10-26T02:49:55Zproblem in using MATLAB solve functionality Hi all,
I have three equations and three unknowns, and I want to use the matlab to solve the eqns for me, however, I realised that the matlab is not giving me a numeric solution. The output I get is just "x","y","z". The code is: (k1, k2, k3 are all known values), the data file is also attached.
syms x y z
path = cell2mat(struct2cell(load("D:\CP\map\MCTS\JPS\after_shortCut")));
k1 = ((path(2,2)-path(1,2))*(path(3,3)-path(1,3)))-((path(3,2)-path(1,2))*(path(2,3)-path(1,3)));
k2 = ((path(2,1)-path(1,1))*(path(3,3)-path(1,3)))-((path(3,1)-path(1,1))*(path(2,3)-path(1,3)));
k3 = ((path(2,1)-path(1,1))*(path(3,2)-path(1,2)))-((path(3,1)-path(1,1))*(path(2,2)-path(1,2)));
eqn1 = ((path(2,1)-path(1,1))*(x-path(1,1)))+((path(2,2)-path(1,2))*(y-path(1,2)))+((path(2,3)-path(1,3))*(z-path(1,3)));
eqn2 = k1*(x-path(1,1))+k2*(y-path(1,2))+k3*(z-path(1,3));
eqn3 = dot((path(2,:)'-path(1,:)'),(path(2,:)'-[x,y,z]'))/norm(path(2,:)'-path(1,:)')*norm(path(2,:)'-[x,y,z]')==dot((path(2,:)'-[x,y,z]'),(path(3,:)'-path(2,:)'))/norm(path(2,:)'-[x,y,z]')*norm(path(3,:)'-path(2,:)');
solve([eqn1 eqn2 eqn3],[x y z])MingCheng Zhanghttps://de.mathworks.com/matlabcentral/profile/authors/12413009tag:de.mathworks.com,2005:Question/248302011-12-28T05:59:39Z2020-10-26T02:48:23Zhow to delcare a 2 dimensional array in matlab?heyy i am trying to declare an 2D array
in c++ it was easy like:
array[i][j]= _value i want to assign_
but in matlab how is it possible? i want to store two values against one field... bubble troublehttps://de.mathworks.com/matlabcentral/profile/authors/3241148tag:de.mathworks.com,2005:Question/6259832020-10-26T02:13:53Z2020-10-26T02:47:52ZPlotting 1000 signals into one graph Hello,
I am currently doing research at my university. Until now, I have been given a signal (which is 1x321 in length), added noise to it, filtered it, and then plotted the output. I was recenly given a set of signals (1000x321) and I am trying to figure out how to go through, doing the above mentioned steps and then plotting them. I know I will need something like:
for (i=1,i<=1000, i++),
to get started but I am not sure exactly how to make it step through and plot each one to the same graph. Any help would be greatly appreciated!Jordan Willishttps://de.mathworks.com/matlabcentral/profile/authors/13483416tag:de.mathworks.com,2005:Question/6259082020-10-25T23:58:27Z2020-10-26T02:47:13ZSplit a cell that contains a stringI have a cell u(38,1) each row has string looking like this :
for example u{1,1} = ''198823 765389 white''
u{2,1} = ''198426 725312 black''
I want the cell u to be divided in 3 colomns such as
u{1,1} = ''198823'' u{1,2}= ''765389'' u{1,3}=''white''
u{2,1} = ''198426'' u{2,1}= ''725312'' u{2,3}=''black''
so basically I want my u(38,1) to become u(38,3)
I have tried strplit, but it seems like it won't work with a cell,
strplit(u,',') %doesn't work'
strplit(u{1,1},',') %works on the first line and returns a cell (1,3)Melissa Ettehttps://de.mathworks.com/matlabcentral/profile/authors/19783382tag:de.mathworks.com,2005:Question/6260032020-10-26T02:46:43Z2020-10-26T02:46:43Zhow to change amplitude? phased.FMCWWaveformHow can I change the amplitude of in "phased.FMCWWaveform" ? Its default value is 1 but i want to change it and i don't know how?
please someone help ne in this issue, thanksKhuram Shehzadhttps://de.mathworks.com/matlabcentral/profile/authors/16024637tag:de.mathworks.com,2005:Question/6253232020-10-25T06:39:54Z2020-10-26T02:46:06Z3D and 2D matrix multiplication in the objective functionI have a 3D A matrix NxNxM and 2D B matrix (NxN), which will be an integer optimization variable matrix for the solver. I want to multiply A and B to obtain (NxNXM) matrix. Then I need to sum all of the elements of the resulting 3D matrix.
My objective function is the following:
ndesign = optimproblem('Objective',sum(A.*B,'all'));
I can do this multiplication if I don't use the solver. However, I receive the following error when I put it in the objective function:
Error using optim.internal.problemdef.ElementwiseOperator/checkIsValid
Argument dimensions 1454-by-1454-by-50 and 1454-by-1454 must agree.
Error in optim.internal.problemdef.Times/checkIsValid
Error in optim.internal.problemdef.Times.getTimesOperator
Error in .*
Error in networkdes (line 290)
ndesign = optimproblem('Objective',sum(A.*B,'all')); % Create optimization problem
I also need to convert my 3D matrix to sparse 3D matrix. I'm using ndSparse library to create it but I could not use it in the objective function again. Thanks in advance.
Edit for more explanations. Here is my optimization script:
A = %(1454x1454x50) 3D matrix
A_sparse = ndSparse(A);
B = optimvar('b', [length(A),length(A)], 'Type', 'integer', 'LowerBound',0,'UpperBound',1);
ndesign = optimproblem('Objective',sum(A.*B,'all')); % Create optimization problem
% ndesign = optimproblem('Objective',sum(A_sparse.*B,'all')); % Create optimization problem for sparse A
ndesign.Constraints.const1 = ( B(diag(B)) == 0 ); % B_ii == 0
ndesign.Constraints.const2 = ( sum(B,'all') == 20 );
opts = optimoptions('intlinprog','Display','off','PlotFcn',@optimplotmilp);
[sol,fval,exitflag,output] = solve(ndesign,'options',opts);ebon Thttps://de.mathworks.com/matlabcentral/profile/authors/20041627tag:de.mathworks.com,2005:Question/3062392016-10-07T14:37:13Z2020-10-26T02:42:58ZFix for " The input to DATENUM was not an array of strings." I am attempting to use datenum on my table (one column, first column) of dates to convert it into a separate variable of just a series of numbers
dataset = readtable('equity_dataset_30.csv');
data = dataset(:,2:31);
date = dataset(:,1);
date_num = datenum(date, 'yyyy-mm-dd');
This last line keeps returning the error: " The input to DATENUM was not an array of strings."
Could someone show what I'm missing here? Ming Auhttps://de.mathworks.com/matlabcentral/profile/authors/8746935tag:de.mathworks.com,2005:Question/6259982020-10-26T02:41:58Z2020-10-26T02:41:58ZWhy a matrix multiply a variable and then be divided by the same variable produce different results?clear all;
matFilename='.\test.tif';
b=mean(mean(imread(matFilename)));
matData=imread(matFilename)*(b/b); %line4
% matData = imread(matFilename)*b/b; %line 5
figure;
imshow(matData,[]);
As the code show above, the b is a number. Why it produces different results when toggling between line 4 and line 5.
The sample image file is attached on the .zip file.xiaoxiao zhaohttps://de.mathworks.com/matlabcentral/profile/authors/14543040tag:de.mathworks.com,2005:Question/6259232020-10-26T00:13:08Z2020-10-26T02:39:12ZRemove first characters from a stringI have a celll u(5,1) that looks like :
u{1,1}=''ART1/TEACH''
u{2,1}=''H0ME/SHOW''
I want to remove the first 5 characters from each of these strings so that :
u{1,1}=''TEACH''
u{2,1}=''SHOW''
How can I do it?Melissa Ettehttps://de.mathworks.com/matlabcentral/profile/authors/19783382tag:de.mathworks.com,2005:Question/6259932020-10-26T02:35:48Z2020-10-26T02:35:48ZHow to track targets in bistatic coordinate?if the measurements are the bistatic range and the bearing, how to track targets?
the target is Tgt, the transmitter is Tx, the receiver is Rx, measurements are r1 + r2 and α
Sen Wanghttps://de.mathworks.com/matlabcentral/profile/authors/18682220tag:de.mathworks.com,2005:Question/6259882020-10-26T02:16:26Z2020-10-26T02:16:26ZHow to use the same equation to get shapes of different sizes and locations.Hi,
I'm trying to get 3 circles stacked ontop of eachother (a snowman) each of a different size (heights of: 80, 50, 30). I'm not sure how to use the same equation (given below) for each of the different parameters. I've tried using a matrix but matlab isn't liking that. Am I making an obvious mistake?
I want to make it look neat so don't want to write out the same equation multiple times.
angles = linspace(0, 2*pi, 500);
radius = [40 25 15];
CenterX = [0 0 0];
CenterY = [40 105 145];
x = radius * cos(angles) + CenterX;
y = radius * sin(angles) + CenterY;
plot(x, y, 'b-', 'LineWidth', 2);
hold on;
plot(CenterX, CenterY, 'k+', 'LineWidth', 3, 'MarkerSize', 14);
grid on;
axis equal;
xlabel('X', 'FontSize', 14);
ylabel('Y', 'FontSize', 14);Cai Beachamhttps://de.mathworks.com/matlabcentral/profile/authors/18038747tag:de.mathworks.com,2005:Question/6259532020-10-26T00:51:52Z2020-10-26T02:15:38ZError While running a while loop (index exceeds number of array elements)clear all
close all
%givens
E0 = 3; %input voltage
ls = 7*10^-14; %value of ls
R = 200; %value of resistor
C = .026; %value of KT/q
V_vec = [];
Vdiode(1) = 1; %initial guess for Vdiode
Vdiode(2)
i=1;
%iterate until difference between last 2 Vdiodes < 10^-6
while abs(Vdiode(i + 1) - Vdiode(i)) > 10^-6
% derivative of f
fprime = -1-ls*R/C * exp(Vdiode(i)/C);
% f at Vdiode
f = E0 - Vdiode(i) - ls * R * (exp(Vdiode(i)/C) - 1);
% new Vdiode
Vdiode(i) = Vdiode(i) - f/fprime;
% store in vector
V_vec(i) = Vdiode(i);
% increment i
i = i + 1;
end
Vdiode
length(V_vec)Mia Loposserhttps://de.mathworks.com/matlabcentral/profile/authors/19568435tag:de.mathworks.com,2005:Question/6259432020-10-26T00:24:44Z2020-10-26T02:08:54ZPlot multiple conditions in same figure using for and if loop.Hi,
I would like to plot the total cases against days tracked for the 6 countries mentioned in key_locations. The code currently only works and plots for a single country because strcmp can only compare two strings, but I would like to compare 6 strings (one for each country) to the cell data and plot the graphs all on the same figure. This is what I've written so far and a sample of the excel sheet is attached.
Thank you
covid_data = readtable('owid-covid-data.xlsx');
key_locations = ["Australia" "China" "India" "Indonesia" "Malaysia" "Vietnam"];
Location = covid_data(:,3);
CC = table2cell(Location); %converts table to cell array
CC1 = table2cell(covid_data);
[R C] = size(covid_data);
for i = 1:R
if strcmp(CC(i),key_locations(1));
totalcases(i)=cell2mat(CC1(i,6));
daystracked(i) = cell2mat(CC1(i,5));
newcases(i) = cell2mat(CC1(i,7));
end
end
totalcases(totalcases == NaN) = []; %NaN is currently undefined
daystracked(daystracked == NaN) = [];
newcases(newcases == NaN) = [];
figure(1) Cate mayhttps://de.mathworks.com/matlabcentral/profile/authors/20029193tag:de.mathworks.com,2005:Question/688522013-03-27T18:19:51Z2020-10-26T02:05:48ZHow do you open a .xlsx file in excel from matlab.I am trying to open up a .xlsx file from matlab, and have it open in excel. Right now I am using the command open(filename). This will open the .xlsx in matlab, but i want it opened in excel. The command opentxt(filename) is nice, because it will open a .txt file in notepad. I am looking for something like that for .xls/.xlsx files in excel. ryanhttps://de.mathworks.com/matlabcentral/profile/authors/2806281tag:de.mathworks.com,2005:Question/6258182020-10-25T21:48:53Z2020-10-26T01:55:27ZRead file with non-uniform lines?Hi. I'm a Matlab newbie. I would like to read in a file where the lines have different formats, as below.
% Coordinates
% Code ID X Y
C 101 0.001 0.001
C 102 1.002 0.002
C 103 1.003 1.003
C 104 0.004 1.004
% Distances
% Code ID From To Dist
D 201 101 103 1.417
D 202 102 104 1.414
If the first character is C, use...
A = textscan(fid,'%c %d %f %f')
If the first character is D, use...
A = textscan(fid,'%c %d %d %d %f')
After, I'd like to assign the data to structs (c.id, c.x, c.y, d.id, d.from, d.to, d.dist), but first I think I just need to get it scanned in. Is it possible to apply some logic to reading the file? Thank you.bene1https://de.mathworks.com/matlabcentral/profile/authors/4985243tag:de.mathworks.com,2005:Question/6259782020-10-26T01:48:43Z2020-10-26T01:48:43ZCurve detection using matlabHello, I have the following image:
And im trying to find the line that goes trough the center of the red line, like this:
Any suggestions?Joseph Cybulhttps://de.mathworks.com/matlabcentral/profile/authors/18146085tag:de.mathworks.com,2005:Question/6259732020-10-26T01:35:11Z2020-10-26T01:35:11Zhow to compute the shanon entropy of my data.If I have some data . How can I compute its shanon entropy? Is there some Matlab builtin function for finding that?
Let my data is as follows:
x=0.005*rand(100,1);Sadiq Akbarhttps://de.mathworks.com/matlabcentral/profile/authors/966774tag:de.mathworks.com,2005:Question/6257582020-10-25T19:13:28Z2020-10-26T01:28:20ZI would like to know how I could plot a hyperbolic function of x and y. I was recently given an assignment for my intro to LaTeX class where I needed to plot the given function: x^(2)/9 - y^(2)/4 = 1. I know that this function is a hyperbola, but I can't seem to get it to work properly. The assignment also asked us to generate a list of no more than 6 values to test. I used the linspace function to come up with an evenly spaced matrix for my x values. This is my code:
function graph_1
clear;
x = linspace(-10,10);
y1 = (2*sqrt(x.^(2)/9)/3);
y2 = -(2*sqrt(x.^(2)/9)/3);
figure(1); clf;
plot(y1, y2, 'b')
set(gca, 'fontsize', 12)
title('(x^2)/9 - (y^2)/4 = 1')
grid on
print(figure(1), '-dpng') % They also asked that we save the figure in documents and then use LaTeX to reference it later.
end Mehmet Arslanhttps://de.mathworks.com/matlabcentral/profile/authors/16067961tag:de.mathworks.com,2005:Question/6259682020-10-26T01:23:14Z2020-10-26T01:23:14ZFilling a Vector with Find FunctionHow can I fill in my x vector with the find function?
I have a code that is used for a Bingo game. I have created a vector of 25 random numbers wth no duplicates, then used that vector to create a bingo card (in the form of a 5x5 matrix) and have set the center to 0, so that the player has a freebe. I have created 12 different vectors that will give you all possible ways to win a bingo (vertical, horizontal, and diagonal win). That is a matrix that is 12x5 and I have labeled Win. The Calll vector is a vector of 50 random integers (no duplicates) that is calling the winning numbers. Therefore, I created the x vector, in the nested for loop so that simulataneously, it will find() where numbers in Call equal to an entire row in the Win matrix, because this is how we know there is a winner. The if statement is used to know whether there is a winner or not, because if there are 5 matches in a row, then there are 5 numbers in the Call, that give the Card a Bingo. It will also show the user their bingo card and that they won. My trouble is debugging the
x = [x, find(Call == Win(i,j))];
line where the x vector is supposed to be filled with the row of Win that matches five numbers in the Call vector to cause a bingo. I will include the part of my code that does all I described (and intended to accomplish) above:
WinStatus = false;
%Using my Call to check my Winning Card
for i = 1:length(Win)
x = [];
for j = 1:length(Win(i,:))
x = [x, find(Call == Win(i,j))];
end
%If the length of x is equal to 5 then there is a winner
if(length(x) == 5)
disp('Winner! :D');
disp('This is your winning card (The zero is your free be): ');
disp(Card);
WinStatus = true;
break
end
end
I have another part of my code that deals when there is a loss. It's just that one line that is causing me trouble. Thank you for your time! Sam Zavalahttps://de.mathworks.com/matlabcentral/profile/authors/19946164tag:de.mathworks.com,2005:Question/6258682020-10-25T23:06:52Z2020-10-26T01:16:53ZManually adjust labels on axis of plot (histogram) Hello all,
I have a set of data I am plotting on an histogram. Because I don't want to completely remove the outliers in my dataset, I manually changed the outlier values to some capped value and created the histogram normally. However, now I want to change the x-axis label for the first column, and last column to show that they might contain outliers. For example, instead of "5", which is generated automatically, it should be "<5". Is there a way to do this?
Vivek Guptahttps://de.mathworks.com/matlabcentral/profile/authors/8940741tag:de.mathworks.com,2005:Question/2828202016-05-06T01:26:51Z2020-10-26T01:16:48ZProgrammatically run and export live scriptI have a set of live scripts that I can save as html and publish for a client to inspect. Right now, I do that by opening one script at a time, hitting F5, and then clicking Save As >> html to save it. I'd like to automate that process. I was hoping |publish('script.mlx','html')| would work, but it doesn't seem to. I can save the *.mlx as .m and publish that, but it changes the layout and formatting, and I'd like to keep those.Joachim Vandekerckhovehttps://de.mathworks.com/matlabcentral/profile/authors/758188tag:de.mathworks.com,2005:Question/6251582020-10-24T23:11:22Z2020-10-26T01:16:06ZRequesting help for piecewise plotingclc
clear
syms r I % I = current, r = radius
a = 2;
b = 5;
c = 7;
B = piecewise(r<=0 & r>=a,((r/a)^2)*I, r>=a & r<=b, I, r>=b & r<=c, (c^2-r^2)/(c^2-b^2), r>c, 0);
fplot(B)
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
grid on
title('\color[rgb]{0,0.5,0.5} Magentic Flux Density Magnitude')
xlabel('\sl \color[rgb]{0,0.5,0.5} r Radial Distance (cm)')
ylabel('\sl \color[rgb]{0,0.5,0.5} H Magnetic field magnitude (A/cm)')
Above is a what I would like to plot, but I recieve errors plotting. Below are my errors, I would like some guidance on how to correct my errors.
piecewise(2 <= r & r <= 5, I, 5 <= r & r <= 7, sym(49/24) - r^2/24, 7 < r, 0)
Error using fplot>singleFplot (line 240)
Input must be a function or functions of a single variable.
Error in fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args) (line 200)
hObj = cellfun(@(f) singleFplot(cax,{f},limits,extraOpts,args),fn{1},'UniformOutput',false);
Error in fplot>vectorizeFplot (line 200)
hObj = cellfun(@(f) singleFplot(cax,{f},limits,extraOpts,args),fn{1},'UniformOutput',false);
Error in fplot (line 166)
hObj = vectorizeFplot(cax,fn,limits,extraOpts,args);
Thanks in advance!Jonathan Hawkinshttps://de.mathworks.com/matlabcentral/profile/authors/12411869tag:de.mathworks.com,2005:Question/6259582020-10-26T01:09:03Z2020-10-26T01:11:06ZI need help on cell array and Imaging processingHi
I am using the following code
close all;
clc;
%% Initalize the data
dataDir= fullfile('Data/');
exts = {'.jpg','.png','.tif','BMP'};
imds = imageDatastore(fullfile(dataDir),...
'IncludeSubfolders',true,'FileExtensions','.jpg','LabelSource','foldernames');
countEachLabel(imds);
[TrainData, TestData] = splitEachLabel(imds, 0.5);
size(TrainData);
countEachLabel(TrainData);
numImages = numel(TrainData.Files);
for i = 1:numImages
img = readimage(TrainData, i);
% img2= imshow(img, 'InitialMagnification', 800);
img3= imresize(img, [100 100]);
img4= imshow(img3, 'InitialMagnification', 800);
drawnow;
Train{i} = (img3); %#ok<SAGROW>
end
hiddenSize = 25;
autoenc = trainAutoencoder(Train,hiddenSize,'MaxEpochs',1000,...
'DecoderTransferFunction','purelin','EncoderTransferFunction','satlin','L2WeightRegularization',0.0004,'SparsityRegularization',4,'SparsityProportion',0.15);
numImages = numel(TestData.Files);
for i = 1:numImages
img5 = readimage(TestData, i);
img6= imresize(img, [100 100]);
img7= imshow(img3, 'InitialMagnification', 800);
drawnow;
Test{i} = (img6); %#ok<SAGROW>
end
xReconstructed = predict(autoenc,Test);
%% Test Images
figure();
for i = 1:10
subplot(4,5,i);
imshow(TestData.Files{i});
end
%% Reconstructed images from TestData
figure();
for i = 1:10
subplot(4,5,i);
imshow(xReconstructed(i))
end
But I got the following error
Error using imageDisplayValidateParams
Expected input number 1, I, to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64, logical
Instead its type was cell.
Error in images.internal.imageDisplayValidateParams (line 11)
validateattributes(common_args.CData, {'numeric','logical'},...
Error in images.internal.imageDisplayParseInputs (line 79)
common_args = images.internal.imageDisplayValidateParams(common_args);
Error in imshow (line 253)
images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
Error in data_process1 (line 51)
imshow(xReconstructed(i))
When I compare to the example,
https://www.mathworks.com/help/deeplearning/ref/trainautoencoder.html
the issue is with Train{i}and Test {i}, The model is not trained probably with given data. When I compared with example in MATLAB for digitTrainCellArrayData and digitTTestCellArrayData I am having problems and my cell array which are not the same as in example
My cell arrays for Train{i}and Test {i} are like this like for example Train{i}
But in the example in MATLAB for digits, digitTrainCellArrayData and digitTestCellArrayData are like this
digitTrainCellArrayData
In addition to that. Range in example is from 0 – 1 while my data is from 0 – 255
Kindly looking for your support Abdussalam Elhanashihttps://de.mathworks.com/matlabcentral/profile/authors/15843739tag:de.mathworks.com,2005:Question/6259632020-10-26T01:10:20Z2020-10-26T01:10:20ZFunction handle: intergal of another integralGood morning everyone, I'm trying to solve a quadruple integral with the function handle. The problem is that between them there is a double integral on a domain R. so I decided to first solve the integrals on the domain R and then integrate the result with respect to the other two variables but I have some trouble.
I know that I could solve symbolically but the "intpoly" function only works with "function handle";
my code is:
mi=[1:2:100]' %where mi, xi, yi are arrays with same length.
xi=[1:3:150]'
yi=[1:4:200]'
B=1.09*log(10) %costant value
fun=@(t,m,x,y) ((B./(t-1943)).*exp(-B.*(m-5.75))).*sum((mi(1:50)-5.75).*(1/pi).*(1./(((x-(xi(1:50)).^2+(y-yi(1:50).^2))))))
t1=1965
t2=2000
m1=5.75
m2=8
G=@(T,M,X,Y) arrayfun(fun,T,M,X,Y)
F=integralN(G,t1,t2,m1,m2,174,180,-35,-41) %if I solve the integralN (not considering the polygon R) there are no mistakes
F2=integral2(@(T,M) intpoly(@(X,Y) G(T,M,X,Y), [177.63,182.17,178.7,175.55,177.63],[-37,-37,-40.87,-39.3,-37]),t1,t2,m1,m2)
%if i solve this last matlab gives me the sequent errors:
Error using arrayfun
All of the input arguments must be of the same size and shape.
Previous inputs had size 14 in dimension 1. Input #4 has size 2
Error in INTEGRALE_SUL_DOMINIO>@(T,M,X,Y)arrayfun(fun,T,M,X,Y)
Error in INTEGRALE_SUL_DOMINIO>@(X,Y)G(T,M,X,Y)
Error in integral2Calc>integral2t/tensor (line 237)
Z1 = FUN(X(VTSTIDX),Y(VTSTIDX)); NFE = NFE + 1;
Error in integral2Calc>integral2t (line 55)
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
Error in integral2Calc (line 9)
[q,errbnd] = integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
Error in integral2 (line 106)
Q = integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);
Error in intpoly (line 40)
z=integral2(f,xmin,xmax,ymin,ymax);
Error in
INTEGRALE_SUL_DOMINIO>@(T,M)intpoly(@(X,Y)G(T,M,X,Y),[177.63,182.17,178.7,175.55,177.63],[-37,-37,-40.87,-39.3,-37])
Error in integral2Calc>integral2t/tensor (line 228)
Z = FUN(X,Y); NFE = NFE + 1;
Error in integral2Calc>integral2t (line 55)
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
Error in integral2Calc (line 9)
[q,errbnd] = integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
Error in integral2 (line 106)
Q = integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);
Error in INTEGRALE_SUL_DOMINIO (line 13)
F2=integral2(@(T,M) intpoly(@(X,Y) G(T,M,X,Y), [177.63,182.17,178.7,175.55,177.63],[-37,-37,-40.87,-39.3,-37]),t1,t2,m1,m2)
>>Thanks for your help! Emanuele Biondinihttps://de.mathworks.com/matlabcentral/profile/authors/9377243tag:de.mathworks.com,2005:Question/6233332020-10-23T00:43:05Z2020-10-26T01:00:04ZHow can I set the number of decimals places displayed on plots and histograms?I am learning about image editing and I have a vector of all the grayscale values that go into an image.
In a histogram of the different pixel values, I would like to display the labels on the graph in standard notation. I'm looking for a MATLAB setting to help me do that, so it will display standard notation by default.
Clement Hiltyhttps://de.mathworks.com/matlabcentral/profile/authors/19415174tag:de.mathworks.com,2005:Question/6259282020-10-26T00:18:41Z2020-10-26T00:48:20ZHow can I import multiple text files in my folder to Matlab? I am trying to import all the text files to matlab and make it an array, I used the following funciton to read in all the text files. But it is given me an error saying that the columns of the second line does not match with the first one, is there a way to skip the first line in the text file?
This is the code that I used:
files = dir('*.txt');
for i=1:length(files)
eval(['load ' files(i).name ' -ascii']);
end
And this is the error:
Error using load
Number of columns on line 2 of ASCII file 10.txt must be the same as previous lines.
Error in Project_1B (line 29)
eval(['load ' files(c).name ' -ascii']);
Zifeng Qiuhttps://de.mathworks.com/matlabcentral/profile/authors/13438737tag:de.mathworks.com,2005:Question/6192382020-10-19T19:39:37Z2020-10-26T00:44:38Zpitch function equation for documentationI was wondering what the equation used for in the pitch function for matlab. I love using this, but would like to document what equation that I am using. Thanks for the support.T Andersonhttps://de.mathworks.com/matlabcentral/profile/authors/6669840tag:de.mathworks.com,2005:Question/6259482020-10-26T00:41:34Z2020-10-26T00:41:34ZOrdering points of a concave shape as if tracing the boundary points in a counter-clockwise fashionI have an ascii file containing a list of (x,y) coordinate-pairs, in order of increasing x, that make the following concave shape when plotted:
In order to run a calculation using this shape, I need to order these points as if I was tracing the shape in a counter-clockwise fashion (in reference to the point CA). I've considered ordering them by increasing angle, however the angle isn't strictly increasing, so the order wouldn't be correct. Using poly2ccw() seems to leave the points in the same order (increasing x). Thoughts?Ryan Hallhttps://de.mathworks.com/matlabcentral/profile/authors/20110302tag:de.mathworks.com,2005:Question/6259382020-10-26T00:22:56Z2020-10-26T00:22:56ZCentering Taylor Series about certain ValueI am trying to work the current code into a taylor series for sin(x) that is centered about (pi/2). I am then trying to evaluate the code at x=pi
I am having trouble trying to center the code about the (pi/2) value and am not sure how to proceed. What should I change in my code to center it correctly?
x = pi; %Where it is evaluated
n = 2; %Number of terms
middleMatrix = zeros(1,n); %Creates matrix to be filled (Size determined by N)
for count = 0:n
middleMatrix(count+1) = (-1)^count*x^(2*count+1)/factorial(2*count+1); %Function to get individual values into matrix
end
answerFin = sum(middleMatrix); %Sets final answer as sum of matrix holding the individual valuesJohn Hallawayhttps://de.mathworks.com/matlabcentral/profile/authors/20110248tag:de.mathworks.com,2005:Question/6259332020-10-26T00:20:49Z2020-10-26T00:20:49ZUnable to use a value of type tf as an index.hi i am trying to implement a pi controller on a plant function and its coming up with the error" Unable to use a value of type tf as an index. "Aadarsh Bijuhttps://de.mathworks.com/matlabcentral/profile/authors/14569557tag:de.mathworks.com,2005:Question/6259182020-10-26T00:09:34Z2020-10-26T00:09:34ZPlot the meandist variable versus the time vectordiffcoeff = (2+13)/200;
nop = 10000;
totaltime = 1000;
x = zeros(nop,1);
y = zeros(nop,1);
for i = 1:totaltime
randdirection = 2*pi*rand(nop,1);
xnew = x + diffcoeff*cos(randdirection);
ynew = y + diffcoeff*sin(randdirection);
plot(xnew, ynew, '.');
axis([-10 10 -10 10]);
axis square;
pause(0.01);
x = xnew;
y = ynew;
meandist = zeros(totaltime,1);
meandist(i) = mean(sqrt(x.^2+y.^2));
t = 1:1:1000 ;
end
figure(2)
plot(meandist(i),t,'.')
I'm new at this and trying to plot the meandist variable I made to the tiem vector of 1:1000, any help would be apprecitaed as I'm supposed to be getting a curve which I am not for some reasonBlake MacPhersonhttps://de.mathworks.com/matlabcentral/profile/authors/19833833tag:de.mathworks.com,2005:Question/6257632020-10-25T19:23:30Z2020-10-26T00:03:02ZIndex exceeds the number of array elements (6) (I´m doing the program for composite simpson 3/8 rule) r = mod(n,3);
if (r ==0)
n = n;
end
x = linspace(alfa,beta,n)';
%evaluamos la función en los puntos de la partición x
f = zeros(n,1);
for k = 1:n
f(k) = feval(fx,x(k));
end
h = x(4)-x(1);
Ix = 0;
% n es multiplo de 3 / n = 3*m / #de subintercalos es: (n)/3 = m.
m = floor(n/3);
for j = 1:m
ind1 = 3*(j-1)+1; ind2 = 3*j-1; ind3 = 3*j; ind4 = 3*j+1;
Ix = Ix + ((3*h)/8)*(f(ind1)+3*f(ind2)+3*f(ind3)+f(ind4));
end
endIvonne Márquez Delgadohttps://de.mathworks.com/matlabcentral/profile/authors/19184277tag:de.mathworks.com,2005:Question/6259132020-10-26T00:01:13Z2020-10-26T00:01:13ZConvert 2D image into 3D (to get the x y z coordinates of the image) I know there have been similar articles related to this but I am not sure if those articles can help me with what I am trying to do.
So I have a regular png 2D image which I want to convert into 3D image so that I can get the x y and z coordinates. Basically, I need those coordinates in order to calculate some volume.
What should be the appraoch to start this? Kajimusugura Hoshinohttps://de.mathworks.com/matlabcentral/profile/authors/19326322tag:de.mathworks.com,2005:Question/6258882020-10-25T23:35:09Z2020-10-25T23:58:09ZDesigning a bandpass filterHow do i design a bandpass filter that is used to eliminate the low and high frequency noises of an eeg signal with a cut off frequency of 0.1- 25 Hz Temisanren Okotiehttps://de.mathworks.com/matlabcentral/profile/authors/19492835tag:de.mathworks.com,2005:Question/6257732020-10-25T19:30:47Z2020-10-25T23:54:36ZHow to select every second number from a file of numbers separated by a commaHello
we were given an assignment in MATLAB at our university.
I have no programming experience with MATLAB whatsoever and now we are required to complete this seemingly daunting assignment.
Could anyone please explain to me where should I even start in completing this assignment. MATLAB code is essentially like reading chinese.
I am currently stuck at writting the code for selecting every second number from a text file full of numbers separated by a comma. The tutor at UNI advises to use a for loop.
I linked the pdf of the assignment and the text document with the numbers. We are supposed to select every second number from a row of 4 numbers. For example: 1 2 3 4 1 2 3 4 1 2 3 4... and every number marked by 2 is the number we have to select.
I have esentially no idea what to do.
Thanks in advanceAlex Dimkohttps://de.mathworks.com/matlabcentral/profile/authors/20108823tag:de.mathworks.com,2005:Question/6258382020-10-25T22:08:47Z2020-10-25T23:51:42Zplot the reflectance spectra of three different pixels for all bands in a hyperspectral imageI need to develop a program that generates a binary mask of a hyperspectral image using spectral band difference based segmentation, and then select three different pixels in the image to plot the reflectance spectra for all the bands. There are 244 individual bands, so each image is considered a separate band. I attached 4 different bands for reference. The goal would be to select a given pixel on the pot, plant, and background and compare the reflectance spectra. Mason Lienhttps://de.mathworks.com/matlabcentral/profile/authors/19182436tag:de.mathworks.com,2005:Question/6258782020-10-25T23:23:13Z2020-10-25T23:49:28ZMatrix dimensions must agree.Hello all,
Not sure why this error "Matrix dimensions must agree." is popping up on line 37. I'm trying to simulate adding an electrode.
Matrix dimensions must agree.
Error in hodgkinhuxeqb (line 37)
Vm = V_in-V_out;
Here is my code:
function dSdt = hodgkinhuxeqb(T,S,I,Nd, D)
%Function hodgkinhuxeq
% Inputs: t - time
% I_add - input current
% v - voltage
%variables
V_in = S(1:6:end-5);
m = S(2:6:end-4);
h = S(3:6:end-3);
n = S(4:6:end-2);
s = S(5:6:end-1);
f = S(6:6:end);
%potentials
g_na = 120;
g_k = 36;
g_l = 0.3;
E_k = -77;
E_na = 50;
E_l = -54;
cm = 1;
tau_s = 6;
tau_f = 2;
esyn = 0;
gsyn = 0.01;
sigma = 0.00179;
V_out = I./(4.*pi().*sigma.*D);
V_out = transpose(V_out);
Vm = V_in-V_out;
% alpha and betas eqs
a_m = -0.1.*(Vm+35)./(exp(-0.1.*(Vm+35))-1);
b_m = 4.0.*exp((-Vm-60)./18);
a_h = 0.07.*exp(-0.05*(Vm+60));
b_h = 1./(1+exp(-0.1*(Vm+30)));
a_n = -0.01*(Vm+50)./(exp(-0.1*(Vm+50))-1);
b_n = 0.125*exp(-0.0125*(Vm+60));
%dv/dt sections
K_1 = (g_k.*n.^4.*(E_k-Vm));
Na_1 = (g_na.*m.^3.*h).*(E_na-Vm);
L_1 = g_l.*(E_l-Vm);
%Isyn = gsyn.*(s(end/3)-f(end/3)).*(esyn-v(end/3));
%derivats m,h,n,s
%dmdt = 0;
%dndt = 0;
%dhdt = 0;
dmdt = a_m.*(1-m)-b_m.*m;
dhdt = a_h.*(1-h)-b_h.*h;
dndt = a_n.*(1-n)-b_n.*n;
dfdt = -f/tau_f;
dsdt = -s/tau_s;
%dVdt = (1/cm).*((K_1)+(Na_1)+(L_1)+gsyn.*(s-f).*(esyn-v));
%membrane current for all the compartments
dVdt = 1./cm.*(g_l.*(E_l-Vm));
%na + k currents for all compartments
dVdt = dVdt + 1./cm.*(g_na.*m.^3.*h.*(E_na-Vm)+g_k.*n.^4.*(E_k-Vm));
% applied stimulus to the first compartment
%dVdt(1) = dVdt(1)+1./cm*Ielec;
%applied stim to middle of dendrite
%dVdt(end/2) = dVdt(end/2)+1./cm*Ielec;
R = 225;
a = 0.001;
dx = 0.001;
r = a/(2*R*dx^2);
% left and right sections
dVdt(2:end) = dVdt(2:end)+r.*(Vm(1:end-1)-Vm(2:end));
dVdt(1:end-1) = dVdt(1:end-1)+r.*(Vm(2:end)-Vm(1:end-1));
%merge output
dSdt = zeros(size(S));
dSdt(1:6:end-5) = dVdt;
dSdt(2:6:end-4) = dmdt;
dSdt(3:6:end-3) = dhdt;
dSdt(4:6:end-2) = dndt;
dSdt(5:6:end-1) = dsdt;
dSdt(6:6:end) = dfdt;
dSdt = [dVdt'; dmdt'; dhdt'; dndt'; dfdt'; dsdt'];
dSdt = dSdt(:);
endNyimatoulie Chamhttps://de.mathworks.com/matlabcentral/profile/authors/19474194tag:de.mathworks.com,2005:Question/6258982020-10-25T23:45:43Z2020-10-25T23:45:43ZHow to created a dashed box around a specific set of data on a plotI want to place a dashed box around various set of points on each of the 6 subplots. Also, If someone could explain why the label for the sixth plot won't appear that would also be very helpful!
Tristan Flanneryhttps://de.mathworks.com/matlabcentral/profile/authors/8682713tag:de.mathworks.com,2005:Question/6258932020-10-25T23:43:57Z2020-10-25T23:43:57Zdrawing complex equation in 2D Dear Folks ,
kindly I need your help to plot the following equation :
P=151920000/w -(2673792000*w^2*cos(w) + w*sin(w)*44299872000i - 80736516720000*cos(w))/(w*(4*w - 729)*(4*w + 729)) + (243072000*w*exp((729i)/4))/((4*w - 729)*(4*w + 729))
w=1e06:100e06:1e09
appreciate your cooperation .Firas Kareemhttps://de.mathworks.com/matlabcentral/profile/authors/18950876tag:de.mathworks.com,2005:Question/6255032020-10-25T12:00:45Z2020-10-25T23:39:09ZComputing distances between nodes (intersections of a grid 40x40) and 21 points located in the cell regions in between the nodes.I am trying to write a script where I take a 2000m x 2000m area broken into a grid where by the grid elements are 50m x 50m. In 21 different location i need to place
sources in the center of particular grid elements and then compute the radial distances from each source location to every node on the grid, so I should be getting
41x41x21= 35301 distances in a logical array as a result. I have been palying with the the script shown below but it is obviously wrong as it returns only 21x41= 861
distances. Can any one help with a suggestion of a different approach ?
close all;
clc;
clear;
X= [225 725 1375 1575 425 1675 475 775 1225 1625 1775 1325 1375 1575 975 725 625 875 125 1575 125]';
YX= [425 425 625 1125 1475 1775 1225 775 775 775 325 1275 275 425 1275 1275 1425 1425 1875 1875 425]';
XP= [0 50 100 150 200 250 300 350 400 450 500 550 600 650 700 750 800 850 900 950 1000 1050 1100 1150 1200 1250 1300 1350 1400 1450 1500 1550 1600 1650 1700 1750 1800 1850 1900 1950 2000];
YP= [0 50 100 150 200 250 300 350 400 450 500 550 600 650 700 750 800 850 900 950 1000 1050 1100 1150 1200 1250 1300 1350 1400 1450 1500 1550 1600 1650 1700 1750 1800 1850 1900 1950 2000];
Xdist = X(:) - XP(:)';
Ydist = YX(:) - YP(:)';
dist = sqrt(Xdist.^2 + Ydist.^2);steven elliotthttps://de.mathworks.com/matlabcentral/profile/authors/5194422tag:de.mathworks.com,2005:Question/6258832020-10-25T23:34:25Z2020-10-25T23:35:06ZGeneralized linear models in MatlabAfter learning to use Matlab this year to process and visualise large databases of acoustic data, I am now looking to do some statistics on my results. My first question has a response variable which is a proportion or a count (number of .wav files which contain boat sound) and my explanatory variables are categorical-time of day (day, night), season (spring, summer, autumn, winter) and site (five different locations). Where, time of day may be influenced by site and so these variables should be nested. Does anyone have any pointers on advice on how to interpret the statistical significance of these results using Matlab? Useful resources, books, web pages?Louise Wilsonhttps://de.mathworks.com/matlabcentral/profile/authors/15959472tag:de.mathworks.com,2005:Question/6251182020-10-24T21:47:59Z2020-10-25T23:34:58Zwhat is the code for bin histogram of fraction to the binPooja Jangrahttps://de.mathworks.com/matlabcentral/profile/authors/19623759tag:de.mathworks.com,2005:Question/6253082020-10-25T06:04:28Z2020-10-25T23:33:07Znntool and training issues.hi all,
As you can see in an image that, even i have applied 4 layer to the network but still i am only able to see 2 layers in property and so i can not change neurons in different layers. please help me why is that happening.bhargav Janihttps://de.mathworks.com/matlabcentral/profile/authors/20103001tag:de.mathworks.com,2005:Question/6258582020-10-25T22:49:09Z2020-10-25T23:29:35ZChange histogram to more barsI am generating random numbers. The histogram has a sample size of 20 but only 5 bars. How can I control the bar numbers?
Mustafa Vuralhttps://de.mathworks.com/matlabcentral/profile/authors/10250393tag:de.mathworks.com,2005:Question/6255382020-10-25T12:51:27Z2020-10-25T23:26:46ZA 200-N force is applied as shown to the bracket ABC. Determine the moment of the force about A.• Define the position vector, resolve the position vector into its components. Print them to the screen. • Define the force vector, resolve the force vectBaran Bilgehttps://de.mathworks.com/matlabcentral/profile/authors/20029848tag:de.mathworks.com,2005:Question/6255432020-10-25T12:53:12Z2020-10-25T23:25:32ZIs slicing one big matrix more efficient than storing smaller matrices in a struct?An example of the former would be:
% allcases =
%
% +---------+------------+------------+------------+-----+-------------+
% | Case ID | Data col 1 | Data col 2 | Data col 3 | ... | Data col 10 |
% +---------+------------+------------+------------+-----+-------------+
% | 1 | scalar | scalar | scalar | ... | scalar |
% +---------+------------+------------+------------+-----+-------------+
% | 1 | scalar | scalar | scalar | ... | scalar |
% +---------+------------+------------+------------+-----+-------------+
% | 1 | scalar | scalar | scalar | ... | scalar |
% +---------+------------+------------+------------+-----+-------------+
% | ... | ... | ... | ... | ... | ... |
% +---------+------------+------------+------------+-----+-------------+
% | n | scalar | scalar | scalar | ... | scalar |
% +---------+------------+------------+------------+-----+-------------+
An example of the latter would be:
% allcases(case_id).matrix =
%
% +------------+------------+------------+-----+-------------+
% | Data col 1 | Data col 2 | Data col 3 | ... | Data col 10 |
% +------------+------------+------------+-----+-------------+
% | scalar | scalar | scalar | ... | scalar |
% +------------+------------+------------+-----+-------------+
% | scalar | scalar | scalar | ... | scalar |
% +------------+------------+------------+-----+-------------+
% | scalar | scalar | scalar | ... | scalar |
% +------------+------------+------------+-----+-------------+
% | ... | ... | ... | ... | ... |
% +------------+------------+------------+-----+-------------+
% | scalar | scalar | scalar | ... | scalar |
% +------------+------------+------------+-----+-------------+
Now, in a loop that goes through the cases, it needs to work with a (smaller) matrix that concerns that case only. Therefore, with the former approach we would slice the matrix (via logical or a find) while in the latter we would just call allcases(case_id).matrix.
Is there a recommended approach between these two, in terms of computational speed?
In my problem, I work with up to 100 cases, and up to 50,000 rows in the matrix containing data for each case.Tarohttps://de.mathworks.com/matlabcentral/profile/authors/6417293tag:de.mathworks.com,2005:Question/6251932020-10-25T00:33:00Z2020-10-25T23:18:41Zhow can i open my *.fig that was saved on R2016b in R2008b?hi
i cant open my figure that was saved on R2016b in Matlab 2008b
what should i do?
i have this error:
Warning: Could not find appropriate function on path loading function handle C:\Program
Files\MATLAB\R2016b\toolbox\matlab\scribe\+matlab\+graphics\+illustration\@ColorBar\doMethod.p>delete_self_cb
> In hgload at 43
In openfig at 72
In open at 153
In uiopen at 196
thnxArifhttps://de.mathworks.com/matlabcentral/profile/authors/14607198tag:de.mathworks.com,2005:Question/6252932020-10-25T05:53:44Z2020-10-25T23:18:27ZPlotting Phase angle in MatlabI am trying to plot 2 phase angle graphs based on two impedance calculations. The problem is when i try to calculate the angle with unwrap(angle(Zc)), the plot looks nothing like it should. I am using 5 different text files as data, those are attached. And below is my code and my graphs, then graphs of what I am supposed to be getting.
clear all;
clc;
load freq1.txt;
load Rzero1.txt;
load Lzero1.txt;
load Rpos1.txt;
load Lpos1.txt;
Czero = 7.524/1e3;
Cpos = 1.2027/1e3;
Gzero = 2/1e8;
Gpos = 2/1e8;
w(1)=0;
Zc(1)=0;
Zcpos(1)=0;
Zcmag(1)=0;
Zcposmag(1)=0;
i=1;
k=1;
n=10;
for i=1:size(Rzero1,1)
w(i) = 2*pi*freq1(i);
Zcmag(i) = abs(((Rzero1(i)+1j*w(i)*Lzero1(i))./(Gzero+1j*w(i)*Czero))); %magnitude of Zc
Zc(i) = sqrt(((Rzero1(i)+1j*w(i)*Lzero1(i))./(Gzero+1j*w(i)*Czero)));
end
for k=1:size(Rpos1,1)
w(k) = 2*pi*freq1(k);
Zcposmag(k) = abs(((Rpos1(k)+1j*w(k)*Lpos1(k))./(Gpos+1j*w(k)*Cpos))); %magnitude of Zc
Zcpos(k) = sqrt(((Rpos1(k)+1j*w(k)*Lpos1(k))./(Gpos+1j*w(k)*Cpos)));
end
figure(1)
semilogx(freq1,Zcmag);
figure(2)
semilogx(freq1,Zcposmag)
Zcphase = unwrap(angle(Zc));
Zcposphase = unwrap(angle(Zcpos));
figure(3);
semilogx(freq1,Zcphase);
figure(4);
semilogx(freq1,Zcposphase);
Zc phase for zero sequence
Zc phase for positive sequence
Matthew Portnoyhttps://de.mathworks.com/matlabcentral/profile/authors/5580279tag:de.mathworks.com,2005:Question/6252482020-10-25T04:07:13Z2020-10-25T23:18:24ZHow to plot forecasted data with corresponding datesI am trying to do ANN load forecasting. Finally, when I plot actual and modelled output, some problem is with the date. It shows a different waveform.I believe the problem is with formatting date and plotting data with respect to it.Please advice how to do date formatting correctly .
Date is read from 2019 , 9th month till 12th month(that is specified from 5834th raw till end)
%reading date
Data=readtable('2019_SysLoad.xlsx');
save 2019_SysLoad.mat Data
testdates=Data((5834:end),1);
%converting dates to array
A = table2array(testdates);
plot(datetime(A),target_test);
i am getting like this .
I am supposed to get like shown below with dates on x aixs:
Kindly advice .
Thanks in advanceNNhttps://de.mathworks.com/matlabcentral/profile/authors/15064601