https://ch.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2021-03-05T11:11:56Ztag:ch.mathworks.com,2005:Question/7638112021-03-05T11:11:56Z2021-03-05T11:11:56ZExtract the INNER white region of an image with black and white intersection.Hello,
I would like to get the inner part of the white region in the image below, the region I want is the red rectangluar part (INNER part of the white region). I do not want the outter part of the white region.
However, with my code below, I can only get the out part of the white region, is there anyone can help me?
Thanks a lot.
%%%%%My code
I = imread(filename);
Igray = rgb2gray(I);
BW2 = Igray < 50;
% Detect rectangle region (inside the line)
BW2 = imclearborder(~BW2);
BW2 = bwareafilt(BW2,1);
% Calculate bounding box
props2= regionprops(BW2,'BoundingBox');
boundingBox2 = props2.BoundingBox;
figure
imshow(BW2)
zhifei xuhttps://ch.mathworks.com/matlabcentral/profile/authors/17365636tag:ch.mathworks.com,2005:Question/7638062021-03-05T11:09:39Z2021-03-05T11:09:39ZHow can I work out the cause of code generation errors in simulink when using the "Import Custom Code" feature?I am trying to build a model which contains a C-Function block using a simple c library (just one header and source file).
However almost any time i make any changes to the header and source and then to the block i get a very unhelpful error message telling me to simply "Fix the errors in your custom code" .
The full error message is this:
Top model targets built:
Model Action Rebuild Reason
=======================================================================
ICCPD_Model Failed Code generation information file does not exist.
0 of 1 models built (0 models already up to date)
Build duration: 0h 0m 2.98s
Error(s) encountered while building custom code simulation target for model 'ICCPD_Model'. Fix the errors in your custom code or disable 'Import custom code' if your custom code has incompatibilities.
Caused by:
Microsoft (R) Manifest Tool
Copyright (c) Microsoft Corporation.
All rights reserved.
mt : general error c101008d: Failed to write the updated manifest to the resource of file "D:\Dropbox\EV Parts\Laptop Code\C++\IC_CPD\EVP_ICCPD_Comms\Demonstrator\ICCCPD_Firmware\Simulink\slprj\_slcc\mOGuHBhlPeYuKKXBoKvpv\mOGuHBhlPeYuKKXBoKvpv_cclib.dll". The system cannot open the device or file specified.
While i am sure that there is an error somewhere that is causing this, i have no idea how to use this message to find the cause.
I am currently only working with only one C Function block with a very simple function so I at least know which block is causing this error, even though it does not mention the block name. But i plan to make my model a lot more complex and will no doubt have bugs along the way which retrigger this problem. But then it will be even harder to diagnose.
Could someone please explain what this error means, i dont know what the file that cant be opened is or what its relevance to my code is?
Is there a way to perhaps access more detailed build logs for the embedded code generation process?
Seneda Nassir-Alihttps://ch.mathworks.com/matlabcentral/profile/authors/11269345tag:ch.mathworks.com,2005:Question/7637112021-03-05T09:33:23Z2021-03-05T11:07:37Zsubplot aligment automatic methodHi,
I would like to know if there is an easy way to align subplots ina figure. Here is my problem.
I have a figure with a subplot with a colorbar (on the right of the plot) and a subplot without a colorbar but with two y axis and relative labels bennith it. I would like the plot to be aligned (meaning the x values of the two subplot should be at the same horizontal location). The only way I found to achive that is to thinker with the 'Position' options of the subplot. Like:
subplot(4,2,6,'Position', [0.095 0.1 0.81 0.1428])
But thsi solution depends on the size of the figure itself and on the screen the figure is beign plotted to (at least that is my guess since I get different results dependig on the screen matlab is plotting it in and if I maximize the figure or not).
minimal working example of the problem:
C = [0 2 4 6; 8 10 12 14; 16 18 20 22];
figure
subplot(2,1,1)
imagesc(C)
colorbar
subplot(2,1,2)
hold on
yyaxis left
plot(C(:)); ylabel('C')
yyaxis right
plot(-C(:)); ylabel('-C')
Real case problem output
Any advice is appriciated!giacomo labbrihttps://ch.mathworks.com/matlabcentral/profile/authors/13691820tag:ch.mathworks.com,2005:Question/4055662018-06-13T23:37:12Z2021-03-05T11:06:33ZHow to read video frames the fastest.I want to read in a video file into matlab, find the average color of each frame and store that. I want to do to it as fast as possible.
v = VideoReader('File.mkv');
numFrames = floor(v.Duration*v.FrameRate); %Get number of frames
data = zeros(numFrames,3); %initialize data structure
parfor_progress(numFrames); %Just for tracking parfor progress
parfor cnt = 1:numFrames
frame = read(v, cnt); %Reading a frame
for i = 1:3
data(cnt,i) = mean2(frame(:,:,i)); %Average of each RGB value for each frame
end
parfor_progress; %Update parfor progress
end
parfor_progress(0) %end Parfor progress bar
toc
The limit seems to be the "read' function, I have tried using the newer 'readFrame' but I can't use parfor with it so it is ultimatly slower. Codey Nackehttps://ch.mathworks.com/matlabcentral/profile/authors/8409109tag:ch.mathworks.com,2005:Question/7636412021-03-05T07:28:45Z2021-03-05T11:04:16ZHow to write a code for the following?
I have two vectors u=[u1 u2 u3 u4]=[1 2 3 4]; and b=[b1 b2 b3 b4]=[1 2 3 4];
For M=4 and N=3, I want a to get a row vector xo of size 1 x M+N-1 such that the general equations for the last two elements of that vector xo are:
x2ndlast=exp(-jpi(N-1)Mcos(u1))+exp(-jpi(N-1)Mcos(u2))+......+exp(-jpi(N-1)Mcos(last element of u))
xLast= exp(-jpi(M-1)Ncos(u1))+exp(-jpi(M-1)Ncos(u2))+......+exp(-jpi(M-1)Ncos(last element of u))
Likewise, I want to get another row vector xe of same size 1 x M+N-1 such that the general equations for the last two elements of that vector xe are:
x2ndlast=exp(-jpi(N-1)Mcos(b1))+exp(-jpi(N-1)Mcos(b2))+......+exp(-jpi(N-1)Mcos(last element of b))
xLast= exp(-jpi(M-1)Ncos(b1))+exp(-jpi(M-1)Ncos(b2))+......+exp(-jpi(M-1)Ncos(last element of b))
Then sum all element of xo in xo. Likewise, sum all elements of xe in xe. Then find
abc=0.0;
for m1=1:M+N-1
abc=abc+(abs(xo(1,m1)-xe(1,m1))).^2; %This is error1.
end
abc=abc/M+N-1;Sadiq Akbarhttps://ch.mathworks.com/matlabcentral/profile/authors/966774tag:ch.mathworks.com,2005:Question/7637712021-03-05T10:16:34Z2021-03-05T11:00:40ZPerform linear regression to obtain kI am given the following data set and given an equation CA/CA0=e^-(kt). I am asked to perform a linear regression to find "k".
t=[0 500 1000 1500 2000 2500 3000];
CA=[0.1 0.0892 0.0776 0.0705 0.0603 0.0542 0.0471];
I am not sure how to use this equation exactly in the code or even if i need to find k. I am new to Matlab, it is a bit confusing
My code so far:
t=[0 500 1000 1500 2000 2500 3000];
CA=[0.1 0.0892 0.0776 0.0705 0.0603 0.0542 0.0471];
c1=polyfit(t,CA,1);
norm(CA-polyval(c1,t))Bebak Sandhuhttps://ch.mathworks.com/matlabcentral/profile/authors/14500275tag:ch.mathworks.com,2005:Question/6116562020-10-12T16:04:41Z2021-03-05T10:55:21Z'Modeling and Simulation of MIMO RF Receiver Including Beamforming' In the example model 'Modeling and Simulation of MIMO RF Receiver Including Beamforming' I was learning the model by running the simulation. For my analysis I changed the frequency F0 from 5GHz to 28 GHz. I changed the frequency tones in the RF configuration block accordingly like shown in image or even if I select automatically select fundamental tones
and when I run I recieve this error message ''An error occurred while running the simulation and the simulation was terminated
Caused by:
['simrfV2_mimo_antenna/Receiver/RF_Receiver/Configuration/Solver Configuration']: Delay history is too long. Decrease the delay time or increase the time step. ''
Can someone tell me where and what to change?Ashwath Balasubramanianhttps://ch.mathworks.com/matlabcentral/profile/authors/16206387tag:ch.mathworks.com,2005:Question/7637362021-03-05T09:48:32Z2021-03-05T10:54:14ZHow i can plot the below sigmoid function?
p=2;%Gradient coefficent
z=[0:0.1:1/2]*1e-3;
G=1-1/2*(((h/2)-z)/(h/2)).^p; Sigmoid fuction
z1=[-1/2:0.1:0]*1e-3;
G1=1/2*(((h/2)+z)/(h/2)).^p; Sigmoid function
How i can plot the sigmoid function in the all thickness [-1/2:1/2] ?
p=2;%Gradient coefficent
z=[0:0.1:1/2]*1e-3;
G=1-1/2*(((h/2)-z)/(h/2)).^p; Sigmoid fuction
z1=[-1/2:0.1:0]*1e-3;
G1=1/2*(((h/2)+z)/(h/2)).^p; Sigmoid function
Hi,
I am trying to plot the below sigmoid function versus all thickness.
Any help on how to do that?
Thanks.Ezzin Hamdihttps://ch.mathworks.com/matlabcentral/profile/authors/4975803tag:ch.mathworks.com,2005:Question/5183532020-04-16T10:31:16Z2021-03-05T10:51:18ZMicrosoft Azure Kinect and MATLAB interfacingHi, I have just received the new Azure Kinect and I would like to interface it with MATLAB (setting parameters, acquiring images/video). Do you have any suggestion on how to start (serial communication or other tools)?
Thank you in advance.
Best,
MarcoMarco Carusohttps://ch.mathworks.com/matlabcentral/profile/authors/5403300tag:ch.mathworks.com,2005:Question/7593892021-03-01T12:58:20Z2021-03-05T10:48:03Z3D contour from obtained dataHello! I
I have a file which contains 3 coordinates (x,y,z) and the value of the function in these coordinates. What code should I use to plot a 3D contour plot?
I attached a picture as an example of what I want to get. Tje contour of the figure will be different, but I know how to plot it.
-----------------------------------------------------------------------------
-1 -1 -1 -20
-0.98 -1 -1 10
-0.96 -1 -1 1
-0.94 -1 -1 25
-0.92 -1 -1 -5
-0.9 -1 -1 6
-0.88 -1 -1 7
-0.86 -1 -1 6
-0.84 -1 -1 9
-0.82 -1 -1 10
-0.8 -1 -1 -2
-0.78 -1 -1 -18
-0.76 -1 -1 -15
-------------------------------------------------------------------------------
File data.txt has 1030302 rows, 9 columns, but only the first 4 columns are important for me.Daria Lonkinahttps://ch.mathworks.com/matlabcentral/profile/authors/21683186tag:ch.mathworks.com,2005:Question/7501892021-02-19T11:25:33Z2021-03-05T10:44:07ZSort an Array with sortrows ( ) with two columnsHey guys,
I'm sorting an 82x4 arraywith sortrows. I want it to be sorted in a descending way. First the second column shall be significant and for tiebreakers the third column.
My code is:
Knotenpaare=sortrows(Auswertung,[2 3],'descend')
where Auswertung is the array. The first 40 rows of the array are sorted beautifully. But at the moment the values in the second column switch from positive to negative the sorting changes.
Why are the values in the third column now ascending?
Is there a better way to sort these kinds of arrays ?
Patrick Benzhttps://ch.mathworks.com/matlabcentral/profile/authors/15649281tag:ch.mathworks.com,2005:Question/7637912021-03-05T10:29:55Z2021-03-05T10:43:57ZError: Array indices must be positive integers or logical values%% Inputs
Q = 0.16; %[m^3/s] flowraten
r_2 = 0.25; %[m]Ydre radius
D_2 = 0.50 %[m]Ydre diameter
b_2 = 0.5 %[m]Blad højden
beta_2 = 75 %[grader] vinklen
U_2 = (r_2 * omega) * 2*pi * 1/60
%Head
H_plot = zeros(50,1);
for Q = 1:1:50;
H = (U_2^2*Q/g - U_2/(pi*D_2*b_2*g*tand(beta_2))); % [m] Beregning af head
H_plot(i)= H;
i = i+1;
end
why do i get this error message: Array indices must be positive integers or logical valuesTrine Høy Oddershedehttps://ch.mathworks.com/matlabcentral/profile/authors/14709900tag:ch.mathworks.com,2005:Question/7595912021-03-01T17:43:19Z2021-03-05T10:42:52ZWhy the "It follows the END that terminates the definition of the function "torusVolArea" " happens?function [V, A] = torusVolArea (a, b)
% Calculating Volume
V = (1/4) * (pi * pi) * (a+b) * ((b-a) * (b-a));
% Calculate area
A = (pi*pi) * ((b*b) - (a*a));
end
% Vector for volume
vol = [];
% Vector for area
ar = [];
% Iterate a
for a = 0.25:4
% Calculate volume and area
[V A] = torusVolArea(a, a+2);
% Store volume in vector
vol = [vol V];
% Store area in vector
ar = [ar A];
endJuan Camilo Chaparro Gualdronhttps://ch.mathworks.com/matlabcentral/profile/authors/19707646tag:ch.mathworks.com,2005:Question/7627962021-03-04T12:30:01Z2021-03-05T10:42:40Zhow to carry roi (image roi overlay) along with object shape moments ? how to (to overlay)carry roi (image roi) along with object shape moments ?
here i have share roi image & object moments images ?
roi image--roi.jpg
moments images -- shap1.jpg,shap2.jpg,shap3.jpg
from moments image shape based to overlay roi image ?
roi image.
moments shape images:
Selva Karnahttps://ch.mathworks.com/matlabcentral/profile/authors/4733665tag:ch.mathworks.com,2005:Question/2437432015-09-18T05:33:00Z2021-03-05T10:40:43Zhow to read h.264 video in the format .mkv into matlab?how to read h.264 video in the format .mkv into matlab?ARJUN K Phttps://ch.mathworks.com/matlabcentral/profile/authors/6530790tag:ch.mathworks.com,2005:Question/7638012021-03-05T10:39:20Z2021-03-05T10:39:20ZHow to plot (x,y)Hi. I'm have to plot variables x and y.
I know the range of x.
Now here's where I'm confused, I have 2 other variables, let's call them a and b
a depends on x;
b depends on a;
y depends on b. So indirectly y depends on x. Does y need to be a variable or vector? How do I plot (x,y)? The code below contains matrices but the idea is what's defined above.
Thanks for your help
clc
clear all
f=3.4:0.01:3.8;
BW=0.4;
fo=3.6;
Rs=0.982472;
Rl=0.982472;
I=eye(8);
S11=zeros(1,41);
M=[0 -0.8231 0 0 0 0 0 0;-0.8231 0 -0.59170 0 0 0 0.0251 0; 0 -0.5917 0 -0.5516 0 -0.0781 0 0;0 0 -0.5516 0 -0.4925 0 0 0;0 0 0 -0.4925 0 -0.5516 0 0;0 0 -0.0781 0 -0.5516 0 -0.5917 0;0 0.0251 0 0 0 -0.5917 0 -0.8231; 0 0 0 0 0 0 -0.8231 0];
R=[Rs 0 0 0 0 0 0 0 ; 0 0 0 0 0 0 0 0;0 0 0 0 0 0 0 0;0 0 0 0 0 0 0 0;0 0 0 0 0 0 0 0;0 0 0 0 0 0 0 0;0 0 0 0 0 0 0 0;0 0 0 0 0 0 0 Rl];
for b=3.4:0.01:3.8
lambda=fo/BW*((b/fo)-(fo/b));
A=lambda*I-R*i+M;
for x=1:
S11(1,x)=1+2*i*Rs*inv(A(1,1));
S11(1,x)=sqrt((real(S11(1,x)))^2+(imag(S11(1,x)))^2);
S11(1,x)=10*log(S11(1,x))
end
end
plot(f,S11);
Johnhttps://ch.mathworks.com/matlabcentral/profile/authors/21454839tag:ch.mathworks.com,2005:Question/7558342021-02-25T11:15:35Z2021-03-05T10:37:12ZPdetool on MATLAB mobileHi everyone, can I use pdetoolbox on MATLAB mobile app?
If I can, how?
Thank youElisa Zanellahttps://ch.mathworks.com/matlabcentral/profile/authors/21564880tag:ch.mathworks.com,2005:Question/7637962021-03-05T10:36:07Z2021-03-05T10:36:07ZUpdate data with SetSourceData in an Excel chart sheet hello everyone, through Matlab I opened an Excel file and I generated a xlBubble3d Chart.
The code is shown in the attached picture "Code".
As Shown in the attached picture "BubblePlot_Now", the Chart takes first 3 columns for first series, next 3 columns for the next series, and soo on.
I would like the chart to plot the first 3 rows for the first series, next 3 rows for the second series and soo on.
I tried to modify the last line of code, as it can be seen in the attached image"Code _next", to try to exchange columns and rows, but it doesn't work and an error message appears, saying: "Undefined function PlotBy".
Does anyone have any advice for me?
Thank youMaria Grazia Di Giorgiohttps://ch.mathworks.com/matlabcentral/profile/authors/8937149tag:ch.mathworks.com,2005:Question/4952432019-12-06T14:39:49Z2021-03-05T10:33:18ZHow do I extract all rows of a struct field that is a character array?I want to extract all rows of a field within a struct. The field is a character array.
For sake of example, the struct is called systemData, with a field called Objects, which has a field called status (among many others). The status field is a char, and has 20 rows.
I'd like to extract all 20 rows of systemData.systemObjects.status
When I try "normal" index operations, I either only get one result, or I get an error.
Here is one attempt, which results in an error:
systemData.Objects.status{:}
Error: Expected one output from a curly brace or dot indexing expression, but there were 20 results.
I also tried this:
test_extract = systemData.Objects.status;
But I only get the first row.
How do I extract all rows?Pat Cannyhttps://ch.mathworks.com/matlabcentral/profile/authors/11948165tag:ch.mathworks.com,2005:Question/7524592021-02-22T10:16:57Z2021-03-05T10:31:28ZFFT and Parseval's TheoremWhen I try to implement Parseval's theorem, I find that results are incorrect in the frequency domain. Here, my code is attached .
t=linspace(0,10,1000);
Ts=t(2)-t(1);
AA=cos(2*pi*t);
TD_Result=trapz(t,abs(AA).^2);
frequencyAxis = ((0:length(t)-1) -ceil((length(t)-1)/2))/length(t)/(t(2)-t(1));
Fs=frequencyAxis(2)-frequencyAxis(1);
AA_S=fftshift(fft(AA));
AA_S=AA_S/(length(t));
Freq_Result=trapz(frequencyAxis,abs(AA_S).^2);
Is the normalization correct? Looking on the spectrum provides amplitude of 0.5 which is correct.Chen Firesteinhttps://ch.mathworks.com/matlabcentral/profile/authors/20072923tag:ch.mathworks.com,2005:Question/7637562021-03-05T10:02:08Z2021-03-05T10:26:37ZSpeed up the codeHello
This code is part of a total code. It calculates the geometrical features of the main problem geometry. However, it takes so much time due to mupadmex. How can I improve it? Similar code is written for the solution of x2 and x3 which I have not copied (due to lack of space).
BTW, if i omit the if imaginary condition, would there be any problem? I mean is it possible that double command generate imaginary numbers?
any clever way of speeding up the code is highly appriciated.
%Slopes of three lines
m1=(P(2,2)-P(1,2))/(P(2,1)-P(1,1)); % line 1
m2=(P(3,2)-P(2,2))/(P(3,1)-P(2,1)); % line 2
m3=(P(4,2)-P(3,2))/(P(4,1)-P(3,1)); % line 3
syms x1 %introducing the variables x1,x2,x3
syms x2
syms x3
int=0; % counting the points of intersection - it has to be 2 at the end, in case there is intersection
Points(2,2)=0; %for preallocation
% intersection of circle with line 3
y3=P(3,2)+m3*(x3-P(3,1));
c3 = (x3-xc)^2+(y3-yc)^2-R^2;
x_sol3 = vpasolve(c3);
y_sol3 = subs(y3,'x3',x_sol3); %convert sym to numeric value in y3
x_sol3 = double(x_sol3);
y_sol3 = double(y_sol3);
if imag(x_sol3(1))==0 && imag(x_sol3(2))==0 % This is to guarantee there is real intersection (not imaginary)
for v=1:2
if x_sol3(v)>P(3,1) && x_sol3(v)<P(4,1)
if v==2 && abs(x_sol3(1)-x_sol3(2))<1e-6 % means if two roots are the same do not count it
int;
else
int=int+1;
Points(int,:)=[x_sol3(v) y_sol3(v)];
end
end
end
end
Pooneh Shah Malekpoorhttps://ch.mathworks.com/matlabcentral/profile/authors/16932213tag:ch.mathworks.com,2005:Question/7341402021-02-02T16:16:16Z2021-03-05T10:25:35ZHow to solve 4 transcendental equations of 4 unknown values?Hi. I have a problem in solving the equations. I have four equations and four unknowns and I have to find those 4 unknown variables. The equations are as follows:
syms Y2 Y3 l2 l3;
2*Y1*tan(t1_1)+Y2*tan(t2_1)+Y3*tan(t3_1)==0;
2*Y1*tan(t1_3)+Y2*tan(t2_3)+Y3*tan(t3_3)==0;
b1== (t1_1*Y1)+(t2_1*(Y2/2)*((sec(t2_1)^2)/(sec(t1_1)^2)))+(t3_1*(Y3/2)*((sec(t3_1)^2)/(sec(t1_1)^2)));
b3== (t1_3*Y1)+(t2_3*(Y2/2)*((sec(t2_3)^2)/(sec(t1_3)^2)))+(t3_3*(Y3/2)*((sec(t3_3)^2)/(sec(t1_3)^2)));
Here Y1, b1, b3, l1, lambda are known values and the unknown variables are Y2, Y3, l2, l3. The above t1 ,t2 ,t3 are in terms of l2 and l3.
Y1=0.02;
l1 = 0.0105;
lambda =[0.0426 0.0400 0.0405 0.0420];
b1=0.1079;
b3=0.03189;
t2_1=(2*pi/lambda(1))*l2;
t3_1=(2*pi/lambda(1))*l3;
t2_3=(2*pi/lambda(3))*l2;
t3_3=(2*pi/lambda(3))*l3;
t1_1=(2*pi/lambda(1))*l1;
t1_3=(2*pi/lambda(3))*l1;
I tried using vpasolve and also defining them as functions for plotting contour graphs. But I'm not able to find a solution of all positive values. Please help me with this. Thank you.LAKKIMSETTI SUNANDAhttps://ch.mathworks.com/matlabcentral/profile/authors/16093363tag:ch.mathworks.com,2005:Question/7628112021-03-04T12:53:31Z2021-03-05T10:25:30Zmultiple default files for uigetfileI selected multiple files with uigetfile. later I call uigetfile again and would like to use the previously selected files as defaults, so that I can easily deselect or add files.
Can anybody help me how to have multiple default files?Andreas Büchelhttps://ch.mathworks.com/matlabcentral/profile/authors/1136352tag:ch.mathworks.com,2005:Question/7636362021-03-05T07:21:05Z2021-03-05T10:25:06Zpwelch ignores peaks in PSD plotHello there. I am studying the PSD plots of various aircraft states, and overlapping different estimation methods (green is analytical, blue is FFT and red is pwelch). As you can see, at 0.03 for the PSD of pitch angle there is a peak of power, which is indicated in the analytical plot but is also visible in the FFT plot. I am now trying to smooth out the FFT with the pwelch method, but does not matter how hard I try, the smoothed function will not detect the peak there.
My question is therefore: is this behavior expected, or there is something that I am not seeing that will allow the pwelch smoothed function to represent the peak as well?
Pietro Campoluccihttps://ch.mathworks.com/matlabcentral/profile/authors/14747384tag:ch.mathworks.com,2005:Question/7625712021-03-04T08:54:20Z2021-03-05T10:24:28Zhow to get average of multiple rows and subtract from one group of average to another Hello,
I have a big file with multiple rows and columns. I need to get the average of every 30 rows. for example from row 1 to 30, 31 to 60, 61 to 90 and so on until the end of the rows. Can anyone help me with this? any kinds of help will be really appriciated.Minionshttps://ch.mathworks.com/matlabcentral/profile/authors/19982062tag:ch.mathworks.com,2005:Question/7637862021-03-05T10:22:30Z2021-03-05T10:22:30ZClassification of hand crafted Features with pre train CNN models How I can classify hand crafted features with Pretrain CNN?Asaf Razahttps://ch.mathworks.com/matlabcentral/profile/authors/18839261tag:ch.mathworks.com,2005:Question/7637812021-03-05T10:21:58Z2021-03-05T10:21:58Zode45 unexpected outputI am trying to use ode45 for modeling a differential equation, or rather a set of codependent differential equations, one for each point of some initial function graph.
I.e., my initial condition is a function representing a part of the unit circle and points shall be shifted according to .
I have determined the exact solution analytically and compared it against the ode45 output, yielding unexpectedly inaccurate results.
Below you find the code for a script to this problem. Running it will plot both the exact and the approximate solution to the differential equation at time for step size .
Using a fixed step size for the initial function graph, I am approximating the derivatives and with order (using finite difference formulas). Hence the error of the ode45 output should be at least somewhere in the region of , but that just doesn't show. I have also tried other ode solvers such as ode23s or ode15s, but none of them really give better results. I have also tried using higher order finite difference formulas, but that also doesn't seem to lead to much better results.
I am wondering whether I am just using ode45 wrong or whether my expectations for the error are just too high (i.e., some numerical misunderstanding). However, I can't seem to figure this out, so any help would be very much appreciated.
% grid
h = 0.01;
x = -0.3:h:0.3;
% ode45 input
t = 0.1;
tspan = [0 t];
y0 = sqrt(1-x.^2);
options = odeset('RelTol',1e-10,'AbsTol',1e-10);
% apply ode45 and store values y1 at time t
[~,y] = ode45(@(t,y) rs(y,h),tspan,y0,options);
y1 = y(end,:);
% exact values
y1exact = sqrt(1-2*t-x.^2);
% compare plots
figure
plot(x,y0,'black',x,y1exact,'blue',x,y1,'red')
axis equal
legend('exact t=0','exact t=0.1','approx.t=0.1')
function f = rs(y,h)
% 1. derivative (O(h^2))
dydx = nan(size(y));
dydx(1) = (-3*y(1)+4*y(2)-y(3))/(2*h); % left edge
dydx(2:end-1) = (y(3:end)-y(1:end-2))/(2*h); % inner points
dydx(end) = (y(end-2)-4*y(end-1)+3*y(end))/(2*h); % right edge
% 2. derivative (O(h^2))
d2ydx2 = nan(size(y));
d2ydx2(1) = (2*y(1)-5*y(2)+4*y(3)-y(4))/(h^2); % left edge
d2ydx2(2:end-1) = (y(3:end)-2*y(2:end-1)+y(1:end-2))/(h^2); % inner points
d2ydx2(end) = (-y(end-3)+4*y(end-2)-5*y(end-1)+2*y(end))/(h^2); % right edge
% right side
f = d2ydx2./(1+dydx.^2);
endKaihttps://ch.mathworks.com/matlabcentral/profile/authors/9142803tag:ch.mathworks.com,2005:Question/7637762021-03-05T10:19:19Z2021-03-05T10:21:43ZInconsistent results when using a Cuda Kernel in MatlabHello,
I have recently come across a problem when using a Cuda kernel: The results I get from the kernel are not always the same even though the input data is always the same.
Note the difference in the third row second column.
This is the Matlab code from the function:
And the Kernel:
Does Matlab perhaps not work well cuDoubleComplex when used inside the kernel?
I also tried to use wait(gpuDevice(1)) after I gathered the data. I thought that perhaps the gpu was not done with the calculation. It did not work.
Can somebody help me?Leoluca Tinzmannhttps://ch.mathworks.com/matlabcentral/profile/authors/20991268tag:ch.mathworks.com,2005:Question/3607632017-10-11T10:49:07Z2021-03-05T10:19:53Z1-D Convoltional Neural network for ECG signal processingDear Sir,
I read the useful comment in https://www.mathworks.com/matlabcentral/answers/331164-convolutional-1d-net by Joss Knight.
I want to use 1-D for ECG classification. I have 5 classes of signal,each one has 651 samples, I want to simulate the proposed method of the following article:
"Application of Deep Convolutional Neural Network for Automated Detection of Myocardial Infarction Using ECG Signals" by Prof. Rajendra Acharya. In their paper, they mentioned the CNN structure as follow:
<</matlabcentral/answers/uploaded_files/90596/t1.jpg>>
I worte the following code in order to define my CNN layers:(assumed that input signal has 651 samples)
layers = [imageInputLayer([1 651])
convolution2dLayer([1 102],3,'stride',1)
maxPooling2dLayer([1 2],'stride',2)
convolution2dLayer([1 24],10,'numChannels',3)
maxPooling2dLayer([1 2],'stride',2)
convolution2dLayer([1 11],10,'stride',1,'numChannels',10)
maxPooling2dLayer([1 2],'stride',2)
convolution2dLayer([1 9],10,'numChannels',10)
maxPooling2dLayer([1 2],'stride',2)
fullyConnectedLayer(30)
fullyConnectedLayer(10)
fullyConnectedLayer(2)
softmaxLayer
classificationLayer];
is it correct? I train my CNN with these layers, but the predicted labels are fixed to one of the classes!
But when I use ony the 4 first layers, the accuracy is very good(98.35%). what happend when I insert the remaining layers?
shahram taherihttps://ch.mathworks.com/matlabcentral/profile/authors/6465712tag:ch.mathworks.com,2005:Question/7596512021-03-01T19:05:10Z2021-03-05T10:18:54ZSetting up a Gibbs Sampler for Multivariate Normal DistributionGood evening,
I am trying to write a code for Gibbs Sampling, for my master thesis. Unfortunately I have litlle to no experience in programming or writing code. Hence, I ran into some troubles.
I have three variables that need to be considered i call them x,y,z for simplicity.
In order to sample from the conditional distribution I need the mean vector and Covarince Matrix. However, i do not know how to write the vectors which are contaning 1x2 matrices.
So for example the mean vector would be {\mathbf {x}}={\begin{bmatrix}{\mathbf {mu}}_{1}\\{\mathbf {mu}}_{2}\end{bmatrix}}{\text{ with sizes }}{\begin{bmatrix}q\times 1\\(N-q)\times 1\end{bmatrix}}. How can i create in the first line my mu1 where I have an 1x1 "matrix" and in the second row my 2x1 matrix with mu2 and mu3?
Maybe someone could help me figuring this problem out?
Thanks in advance!
Best, Lukas Lukas Rieglerhttps://ch.mathworks.com/matlabcentral/profile/authors/6199560tag:ch.mathworks.com,2005:Question/1690922015-01-06T17:03:00Z2021-03-05T10:17:01ZHow to choose the parameters of vision.ForeGroundDetector ?Hi everyone,
I am trying to use the ForegroundDetector of the computer vision toolbox in order to detect moving objects in a grayscale image.
However, I encounter some trouble to choose the right parameters of the function, that is to say:
- number of gaussians
- number of training frames
- learning rate
- initial variance.
Is there any tip to determine the best parameters, or is it only empirical depending on the images ?
I feel like the crucial parameter is the initial variance for me. But I am not really familiar with statistics and image processing, so that I don't really understand well what these parameters are...
Thanks for any help.Benjaminhttps://ch.mathworks.com/matlabcentral/profile/authors/5344430tag:ch.mathworks.com,2005:Question/7637612021-03-05T10:15:15Z2021-03-05T10:16:27ZHow to discretize a nonlinear system in simulink?
Hello to all
I have a question related to discretizing a nonlinear system in simulink.
I have the following continuous equations which I want to discretize in order to be able to design a controller for.
dx1/dt1= ( u1 / sin(u2) ) * x2
dx2/dt=(u2/cos(x1)) *u1
I used matlab function in simulink to implement thess equations but my problem is I do not know how to discrete them in simulink.
thanks
Jason Jameshttps://ch.mathworks.com/matlabcentral/profile/authors/21723137tag:ch.mathworks.com,2005:Question/7627862021-03-04T12:17:10Z2021-03-05T10:15:59ZPARFOR in real applicationsI've installed the Parallel Computing Toolbox for some experiments with my code. To my surprise none of the codes run faster with PARFOR compared to sequential FOR loops.
Examples:
https://www.mathworks.com/matlabcentral/answers/762196-how-can-i-efficiently-add-multiple-arrays-generated-in-a-loop
Another example was a simple loop calling the external lame.exe function:
lamebin = 'C:\Program_\lame3.99.5\lame.exe';
switches = ' -m j -h -V 1 -q 2 --vbr-new --nohist';
WavFiles = dir(fullfile(Folder, '*.wav'));
parfor iWav = 1:nFile
aFile = fullfile(Folder, WavFiles(iWav).name);
[aPath, aFile] = fileparts(aFile);
aMP3 = fullfile(aPath, [aFile, '.mp3']);
[s, w] = dos([lamebin, switches, '"', aFile, '" "', aMP3, '"']);
end
Both examples take about the double time than a FOR loop on my 2 core CPU, but there is no acceleration on the 4 core also. The RAM is not exhausted in both cases.
Questions:
Are there obvious mistakes in my naive approachs?
How do you use PARFOR in your applications to accelerates the processing on a pool with 2 or 4 local workers? I know the examples from the documentation, but I was not successful yet to implement it in my codes.Janhttps://ch.mathworks.com/matlabcentral/profile/authors/869888tag:ch.mathworks.com,2005:Question/7604562021-03-02T14:14:17Z2021-03-05T10:15:55ZAdding a label to a data point on a graph that can be toggled to view by clicking on itHi all,
I am wondering if this is possible?
I am plotting using the plot function to make my graph and adding the labels to the points using the text function.
The problem with this is is that I am generating alot of data points and I can't read them individualy easily.
It would be ideal if there is a way to have it so that it plots the points as it's doing now then when I click on the point with the label I want to see this pops up.
Any help is appreciated.
Thanks,
OllieOliver Horrobinhttps://ch.mathworks.com/matlabcentral/profile/authors/19102397tag:ch.mathworks.com,2005:Question/7637662021-03-05T10:15:46Z2021-03-05T10:15:46ZMatlab example file _SoC calculation
In the matlab example,
https://www.mathworks.com/help/physmod/sps/ug/24-hour-simulation-of-a-vehicle-to-grid-v2g-system.html;jsessionid=1df77fb2c8bbfdb8354c9c32ae7f
each vehicle final SoC is calculated assuming that certain number of vehicles's initial SoC and plug in status are common for each profile.How can i modify the simulink block or even with a matlab code , if i want to individually enter 'n' number of vehicles's initial SoC and plug in details (instead of assuming certain number like 35,25 etc under each profile)?
Please advice NNhttps://ch.mathworks.com/matlabcentral/profile/authors/15064601tag:ch.mathworks.com,2005:Question/7581592021-02-27T19:33:50Z2021-03-05T10:08:05ZMatlab R2020b gibberish fontHi,
I have a font problem in Matlab R2020b (Windows 10), it just looks gibberish.
Changing fonts in the "Preferences --> Font" does not help. I also read somewhere that one might try right-click on all the fonts in the Windows Fonts folder and "install for all users". In that case, I have the gibberish font in Windows itself.
Any thoughts what might be the problem? I am pretty sure that it should be a corrupted font, but I already tried to "reset" the fonts settings in Windows and that did not help either.
Thank you.Stanislav Musikhinhttps://ch.mathworks.com/matlabcentral/profile/authors/15796735tag:ch.mathworks.com,2005:Question/7625662021-03-04T08:49:32Z2021-03-05T10:07:32ZHow to deal with nested arrays where the columns and rows are in different dimensions?Hello everyone,
In some previous questions I have asked about defining a specific data structure which gave me splendid answers and a better understanding of organizing those data. Now, for a deeper meaning I would like to know the following:
I have a (72x1 cell) which content is defined by the following block/section:
COLUMN1
ROW1 Text Nr.1
ROW2 2345x3 double
ROW3 Text Nr.2
....times 24 to get the mentioned 72x1 cell array
My goal now is to unnest the 2345x3 double contents in a way, that I obtain the following data order:
COLUMN1 COLUMN2 COLUMN3
Text Nr.1 (empty) (empty)
value 1 value 1 value 1
value 2 value 2 value 2
value 3 value 3 value 3
value 4 value 4 value 4
value 5 value 5 value 5
value 6 value 6 value 6
value 7 value 7 value 7
etc. etc. etc.
Text Nr.2 (empty) (empty)
Text Nr.1 (empty) (empty)
value 1 value 1 value 1
value 2 value 2 value 2
value 3 value 3 value 3
value 4 value 4 value 4
value 5 value 5 value 5
value 6 value 6 value 6
value 7 value 7 value 7
etc. etc. etc.
Text Nr.2 (empty) (empty)
However this requires me to know about the new shifted positons without overwriting any data:
I tried to write a code with a (for loop?) but I am even unsure how to start nor to implement my thought process in a proper solution.
Hence I would like to know a method which allows me to unnest the above mentioned example into a cell array (N x 1) where N of course is the expanded version of the old nested cell array.
Stay safe and healthy,
David
Additional Notes:
For anyone asking about my intenton behind this question: I succesfully printed some parts in 3D printer yesterday using some of your answers by exporting those into different gcode converters which require different data structures depending on the current used software. In my upcoming research I would like to establish a readable communication path between some gcode readers and 3d printers. Therefore I have already adjusted my code for exporting finished data files as well as textboxes for inputing new data. The only struggle that I am currently dealing is the fact, that I am not familiar with the matlab cell editing operations which lead me to your much more refined approach regarding this matter. David Mrozekhttps://ch.mathworks.com/matlabcentral/profile/authors/21647186tag:ch.mathworks.com,2005:Question/7634412021-03-05T00:04:48Z2021-03-05T10:07:02ZGetting parts of string with for loopHi hopefully u can help me!
I have the attached string (picture) and now i want to get from every string in every column the word between the last \ and dot. So for example for the first column i would like to get Gös-Schb2_Ma142-Schb.
The problem is that i will have files later with a different pattern. So its important that i can find with the code the last backslash and dot. My code is:
pointLocation = strfind(A, '.');
underlineLocation = strfind(A, '\');
firstPart = A(underlineLocation(end):pointLocation(end));
But its not working at all...maybe u can help me?Benedikt Skurkhttps://ch.mathworks.com/matlabcentral/profile/authors/20048220tag:ch.mathworks.com,2005:Question/5098552020-03-09T12:46:21Z2021-03-05T10:01:06ZError : unable to connect to host. sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested targetinstallation error matlab2019Emanuele De Astishttps://ch.mathworks.com/matlabcentral/profile/authors/17687328tag:ch.mathworks.com,2005:Question/7637512021-03-05T10:00:14Z2021-03-05T10:00:14ZOutput argument 'g1' is not assigned on some execution paths.Hello, I have been trying to insert this function in my simulink with used defined matlab function block in order to implement the attached logic table. However I get the errror "Output argument 'g1' is not assigned on some execution paths".
Function:
function [g1,g2,g3] = fcn(Bai,Bao,Bbi,Bbo,Bci,Bco)
if Bao==1
if Bbo==0 && Bco==0 %region 1
if Bai==1 && Bci==0
if Bbi==0 %V1
g1=1;
g2=0;
g3=0;
elseif Bbi==1 %V2
g1=1;
g2=1;
g3=0;
else %V0
g1=0;
g2=0;
g3=0;
end
end
elseif Bbo==1 && Bco==0 %region 2
if Bbi==1 && Bci==0
if Bai==1 %V2
g1=1;
g2=1;
g3=0;
elseif Bai==0 %V3
g1=0;
g2=1;
g3=0;
else
g1=0; %V0
g2=0;
g3=0;
end
end
elseif Bbo==0 && Bco==1 %region 6
if Bai==1 && Bbi==0
if Bci==1 %V6
g1=0;
g2=0;
g3=01;
elseif Bci==0 %V1
g1=1;
g2=0;
g3=0;
else
g1=0; %V0
g2=0;
g3=0;
end
end
else
end
elseif Bco==1
if Bao==0 && Bbo==1 %region 4
if Bai==0 && Bci==1
if Bbi==1 %V4
g1=0;
g2=1;
g3=1;
elseif Bbi==0 %V5
g1=0;
g2=0;
g3=1;
else %V0
g1=0;
g2=0;
g3=0;
end
end
elseif Bao==0 && Bbo==0 %region 5
if Bbi==0 && Bci==1
if Bai==0 %V5
g1=0;
g2=0;
g3=1;
elseif Bai==1 %V6
g1=0;
g2=1;
g3=1;
else
g1=0; %V0
g2=0;
g3=0;
end
end
else
end
elseif Bbo==1 && Bao==0 && Bco==0 %region 3
if Bai==0 && Bbi==1
if Bci==0 %V3
g1=0;
g2=1;
g3=0;
elseif Bci==1 %V4
g1=0;
g2=1;
g3=1;
else
g1=0; %V0
g2=0;
g3=0;
end
end
else
g1=0;
g2=0;
g3=0;
end
end
I have checked in script file and it works perfectly. Also, I have included all the conditions in the code.
Please help me with this.
Thanks and regardsJugal Mistryhttps://ch.mathworks.com/matlabcentral/profile/authors/12603271tag:ch.mathworks.com,2005:Question/7625512021-03-04T08:42:47Z2021-03-05T09:57:57ZHow to change a sequence of integers?I am new to Matlab and coming up already with a tricky question. Suppose a sequence of integers
[2 1 3 4 1 1 3 1 2 1 2 2 5 3 2];
that I want to change according to the following rules:
When there is a one not followed or preceeded by another one, I want to replace the one, the preceeding and following number by the sum of the two numbers around the one.
If for two given ones, the preceeding and following numbers overlap, I want to add them allogether.
So in my example, I should obtain:
[5 5 5 4 1 1 7 7 7 7 7 2 5 3 2]
The first three numbers turn to be 5 because I add 2 + 3, according to rule 1. The next three numbers 4 1 1 remain unchanged, also according to rule 1. The then coming 5 numbers [3 1 2 1 2] should all be added together, because of rule 2. Lastly, 2 5 3 2 remain unchanged.
I cannot figure out how to do this. Perhaps there is a way of writing a recursive function that picks a one, checks if and how much numbers have to be added from the left and then looks at the right and finally sums the numbers up. Does anyone have a clue? Many thanks in advance
S Hhttps://ch.mathworks.com/matlabcentral/profile/authors/9560353tag:ch.mathworks.com,2005:Question/7637462021-03-05T09:57:53Z2021-03-05T09:57:53ZIndex in position 2 exceeds array boundsI seem to get the same error every time I try to run the code. (Index in position 2 exceeds array bounds)
for k =1:length(real_mat)
% real_mat(:,k+1) = real_mat(:,k)+1;
D = abs(bsxfun(@minus,real_mat(:,k),new_matrix(:,3).'));
[~,X] = min(D,[],2);
Array_Of_Path_x(:,k) = new_matrix(X,1);
Array_Of_Path_y(:,k) = new_matrix(X,2);
end
I have tried "real_mat(:,k+1) = real_mat(:,k)+1;" which doesnot really give the expect answer. What am I doing wrong? How can I get rid of this problemBilly Joneshttps://ch.mathworks.com/matlabcentral/profile/authors/21739903tag:ch.mathworks.com,2005:Question/7630262021-03-04T15:58:44Z2021-03-05T09:57:49Znonlcon with 2 possible valuesI am using fmincon to optimize a space trajectory. My controls are the thrust three directions (radial(Tr), tangential(Tt) and normal(Tn)).
During my trajectory, I want the thrust to be either equal to the maximum possible value (Tmax) available or null. To express this constrain I want to use
sqrt(Tr^2+Tt^2+Tn^2)
ceq=[ or
sqrtT(r^2+Tt^2+Tn^2)-Tmax
How can I express this nonlinear constrain in my script? is it possibile to write the constrain with an or operator? Alessia De Iuliishttps://ch.mathworks.com/matlabcentral/profile/authors/19558626tag:ch.mathworks.com,2005:Question/7637412021-03-05T09:56:04Z2021-03-05T09:56:04Zdesigning a trial structure with psychtoolboxHi all,
I am trying to use psychtoolbox to design an experiment where the trials are structured as described in the attached .pdf. Any insights on how this can be done or any example code that could be shared would be much appreciated.HBhttps://ch.mathworks.com/matlabcentral/profile/authors/5716959tag:ch.mathworks.com,2005:Question/5142522020-03-31T10:25:43Z2021-03-05T09:55:54ZSimulink model "running" from stand-alone "app designer" appI am developing an app with app designer. The app employs Simulink models. I want to use the app through the standalone Desktop App.
The app runs/works correctly in the Matlab environment. However, I use the MATLAB compiler to create the app, then I execute the app and the app fails when the simulink code is executed.
simOut=sim('MODEL.slx','StopTime','TimeEnd','FixedStep','1','StartTime','0');
How can I run a Simulink model with a standalone desktop app?
Thank you in advanceAitor Milohttps://ch.mathworks.com/matlabcentral/profile/authors/14831469tag:ch.mathworks.com,2005:Question/7636812021-03-05T09:09:28Z2021-03-05T09:53:00ZAntenna radiation pattern rotationHello everyone,
I'm having some problems with a rotation of the antenna field. Here my antenna pattern now, after a decomposition of the theta and phi fields in x,y,z-ones:
and I'd like to rotate the main lobe along the x-axis. Do you have any idea to how I shoud do it? (without the phased array toolboox - so the rotpad function- because I do not have the toolboox).
I tried applying the matrix rotation on the 3(x,y,z)-components but it just gives me a kind of "change of name". Here the results:
But as you can see the main lobe is now in the z-component (right for my purpose) but not along the x-axis.
Thank you a lot in advance.
Marina Lottihttps://ch.mathworks.com/matlabcentral/profile/authors/8123894tag:ch.mathworks.com,2005:Question/3916302018-03-30T11:01:26Z2021-03-05T09:51:56ZHow can I fix propagation speed error using Simscape Power System?I’m running 2017b, using a model I _think_ was created in 2015x. When I try to run the model, I receive the following error:
“A propagation speed of...has been found for Mode 1 Block 10. Propagation speed must be < 300000 km/s.”
Analysis of the model forms part of a university coursework, and I can’t see anything obvious to change to allow it to run correctly. Thanks. Euan McLeanhttps://ch.mathworks.com/matlabcentral/profile/authors/12065285tag:ch.mathworks.com,2005:Question/7572542021-02-26T17:24:59Z2021-03-05T09:48:17ZHow to generate C++ Code from predictAndUpdateState() function of LSTM NN?Hi lovely people,
we are working on a project where we want to use a Time-Series LSTM Neural Network to forecast multiple time steps in the future by using the predictAndUpdateState() function iteratively in a loop, so the network can keep its state, while on every iteration the network is fed with input from its own previous predictions and other forecast data we aquire from different sources. In general it looks like this:
net = getLSTMNN;
cT = initialValue;
numTimeSteps = 120;
XInput = (cT, getCurrentData);
for i = 1:numTimeSteps
if i ~= 1
XInput = (YPred(:,i-1), getForecastData(i-1));
end
[net,YPred(:,i)] = predictAndUpdateState(net,XInput);
end
For context: the LSTM is intended to be used as a predictor within a model predictive controller.
We are aware that the official Matlab Ref-Page of predictAndUpdateState does not list C++ Code generation as supported, only GPU CUDA Code for NVIDIA GPUs, which we cannot make use of. But there is an example where the predictAndUpdateState() of a Stateful LSTM is used to generate Code for an ARM-based Rasperry Pi (Link). Thats why we are searching for a way to generate "pure" C++ CPU Code from a predictAndUpdateState() function which is not CUDA dependent or intended for ARM systems.
Any help, advice or tips on how to achieve this would be greatly appreciated!
EDIT: We are on 2020b.
Many thanks,
SimonSimon Linekhttps://ch.mathworks.com/matlabcentral/profile/authors/20391864tag:ch.mathworks.com,2005:Question/7635612021-03-05T04:46:14Z2021-03-05T09:47:55Zevaluation of anonymous function r=1e-2;
V0=1e-6;
m=1;
if(m<4)
V=@(x) (0.5+0.5.*sign(r.^2-x.^2))*V0;
else
abort
end
In this piece of code, how are the values assigned to V?
The fuction V is not used in any other block of code. What are the values of x? How is V evaluated?
Please clarify this?Kaveri Ahttps://ch.mathworks.com/matlabcentral/profile/authors/15391328tag:ch.mathworks.com,2005:Question/7637262021-03-05T09:47:04Z2021-03-05T09:47:04ZSelecting Specific Tab in spreadsheetHi (I am fairly new to MATLAB so apologies for any ignorance in the below):
I am trying to import a datasheet with multiple tabs which is outputted as a results file by a separate piece of software. The number of tabs is likely to be different each time I import this. I am interested in only a few 'types' of the tabs in this spreadsheet and these always end in "_Main" (the tabs not of interest do not end in "_Main". Ultimatey I want a script that can import these spreadsheets, identify the tabs of interest and then add a couple of columns (multiply a couple of the other existing columns), with which I am hoping to create some graphs from.
So far I have been able to bring in the data using the following:
mydata = importdata('Test1.xlsx');
When I open the data in the workspace, the data has several subheadings (data, textdata, colheaders). Within the 'data' section of this, I can see the various tabs from my spreadsheet (some with "_Main" in the title and some without). Then I have identified the tabs of interest and output them in a separate array called "g". I have done this via the following:
for i=1:numel(fnames)
if contains(fnames(i), "Main")
bingo(i) = 1 ;
else bingo(i) = 0 ;
end
end
Target=find(bingo) ;
for counter2=1:numel(Target)
TempValue1 = Target(1,counter2)
g(TempValue1,1)= fnames(TempValue1,1)
end
However, my problem is now that I am not sure how I can call up those identified tabs. I can call this up from the command window as:
mydata.data.EXAMPLE_Main
But is there a way I can codify this? e.g can I call up mydata.data.<the 2nd tab> ?
Thanks,
Chris
CHRIS HARRISONhttps://ch.mathworks.com/matlabcentral/profile/authors/11518499