Category: Matlab
Category Archives: Matlab
Filled error bars to a plot
Hello,
I have been trying to create some error bars in my MATLAB script. However, I think there are some problems. I have made a figure with three plots, and I wish to have "filled" error bars for the DO and pH. Additionally, the error bars for biomass have lines between the points, which I don’t know how to remove. It would be nice if only the error bars were present.
I have inserted the code to my plot and data. Excel file is attached aswell.
growth = readtable("growthWT2.xlsx")
time = [growth.Time_h_];
timeOD = [growth.Time_h__1];
DO_1 = [growth.O21];
DO_2 = [growth.O22];
DO_3 = [growth.O23];
mean_DO = [growth.MeanO2];
S_DO = [DO_1 DO_2 DO_3];
stand_DO = std(S_DO,0,2);
pH_1 = [growth.pH1];
pH_2 = [growth.pH2];
pH_3 = [growth.pH3];
mean_pH = [growth.meanPH];
S_pH = [pH_1 pH_2 pH_3];
stand_pH = std(S_pH,0,2);
Bio_1 = [growth.biomass1];
Bio_2 = [growth.biomass2];
Bio_3 = [growth.biomass3];
mean_bio = [growth.MeanBio];
S_bio = [Bio_1 Bio_2 Bio_3];
stand_bio = std(S_bio,0,2);
% mean values
t = tiledlayout(2,1);
nexttile
yyaxis left
fill([time, flip(time)], [mean_DO+stand_DO, flip(mean_DO-stand_DO)], ‘b’, ‘FaceAlpha’, 0.3, ‘EdgeColor’, ‘none’)
hold on
plot(time, mean_DO, ‘b’)
ylabel(‘DO’)
yyaxis right
fill([time, flip(time)], [mean_pH+stand_pH, flip(mean_pH-stand_pH)], ‘r’, ‘FaceAlpha’, 0.3, ‘EdgeColor’, ‘none’)
hold on
plot(time,mean_pH, ‘r’)
ylabel(‘pH’)
legend(‘DO’, ‘DO Std Dev’ ,’pH’, ‘pH Std dev’)
nexttile
plot(timeOD,mean_bio,’o’)
hold on
errorbar(timeOD, mean_bio, stand_bio)
ylabel(‘Biomass [g/L]’)
legend(‘Biomass’, ‘Biomass Std Dev’)
title(t,’Growth parameters of PR01 average value’)
xlabel(t,’Time [h]’)Hello,
I have been trying to create some error bars in my MATLAB script. However, I think there are some problems. I have made a figure with three plots, and I wish to have "filled" error bars for the DO and pH. Additionally, the error bars for biomass have lines between the points, which I don’t know how to remove. It would be nice if only the error bars were present.
I have inserted the code to my plot and data. Excel file is attached aswell.
growth = readtable("growthWT2.xlsx")
time = [growth.Time_h_];
timeOD = [growth.Time_h__1];
DO_1 = [growth.O21];
DO_2 = [growth.O22];
DO_3 = [growth.O23];
mean_DO = [growth.MeanO2];
S_DO = [DO_1 DO_2 DO_3];
stand_DO = std(S_DO,0,2);
pH_1 = [growth.pH1];
pH_2 = [growth.pH2];
pH_3 = [growth.pH3];
mean_pH = [growth.meanPH];
S_pH = [pH_1 pH_2 pH_3];
stand_pH = std(S_pH,0,2);
Bio_1 = [growth.biomass1];
Bio_2 = [growth.biomass2];
Bio_3 = [growth.biomass3];
mean_bio = [growth.MeanBio];
S_bio = [Bio_1 Bio_2 Bio_3];
stand_bio = std(S_bio,0,2);
% mean values
t = tiledlayout(2,1);
nexttile
yyaxis left
fill([time, flip(time)], [mean_DO+stand_DO, flip(mean_DO-stand_DO)], ‘b’, ‘FaceAlpha’, 0.3, ‘EdgeColor’, ‘none’)
hold on
plot(time, mean_DO, ‘b’)
ylabel(‘DO’)
yyaxis right
fill([time, flip(time)], [mean_pH+stand_pH, flip(mean_pH-stand_pH)], ‘r’, ‘FaceAlpha’, 0.3, ‘EdgeColor’, ‘none’)
hold on
plot(time,mean_pH, ‘r’)
ylabel(‘pH’)
legend(‘DO’, ‘DO Std Dev’ ,’pH’, ‘pH Std dev’)
nexttile
plot(timeOD,mean_bio,’o’)
hold on
errorbar(timeOD, mean_bio, stand_bio)
ylabel(‘Biomass [g/L]’)
legend(‘Biomass’, ‘Biomass Std Dev’)
title(t,’Growth parameters of PR01 average value’)
xlabel(t,’Time [h]’) Hello,
I have been trying to create some error bars in my MATLAB script. However, I think there are some problems. I have made a figure with three plots, and I wish to have "filled" error bars for the DO and pH. Additionally, the error bars for biomass have lines between the points, which I don’t know how to remove. It would be nice if only the error bars were present.
I have inserted the code to my plot and data. Excel file is attached aswell.
growth = readtable("growthWT2.xlsx")
time = [growth.Time_h_];
timeOD = [growth.Time_h__1];
DO_1 = [growth.O21];
DO_2 = [growth.O22];
DO_3 = [growth.O23];
mean_DO = [growth.MeanO2];
S_DO = [DO_1 DO_2 DO_3];
stand_DO = std(S_DO,0,2);
pH_1 = [growth.pH1];
pH_2 = [growth.pH2];
pH_3 = [growth.pH3];
mean_pH = [growth.meanPH];
S_pH = [pH_1 pH_2 pH_3];
stand_pH = std(S_pH,0,2);
Bio_1 = [growth.biomass1];
Bio_2 = [growth.biomass2];
Bio_3 = [growth.biomass3];
mean_bio = [growth.MeanBio];
S_bio = [Bio_1 Bio_2 Bio_3];
stand_bio = std(S_bio,0,2);
% mean values
t = tiledlayout(2,1);
nexttile
yyaxis left
fill([time, flip(time)], [mean_DO+stand_DO, flip(mean_DO-stand_DO)], ‘b’, ‘FaceAlpha’, 0.3, ‘EdgeColor’, ‘none’)
hold on
plot(time, mean_DO, ‘b’)
ylabel(‘DO’)
yyaxis right
fill([time, flip(time)], [mean_pH+stand_pH, flip(mean_pH-stand_pH)], ‘r’, ‘FaceAlpha’, 0.3, ‘EdgeColor’, ‘none’)
hold on
plot(time,mean_pH, ‘r’)
ylabel(‘pH’)
legend(‘DO’, ‘DO Std Dev’ ,’pH’, ‘pH Std dev’)
nexttile
plot(timeOD,mean_bio,’o’)
hold on
errorbar(timeOD, mean_bio, stand_bio)
ylabel(‘Biomass [g/L]’)
legend(‘Biomass’, ‘Biomass Std Dev’)
title(t,’Growth parameters of PR01 average value’)
xlabel(t,’Time [h]’) filled error bars, plot MATLAB Answers — New Questions
Filter Design for SHM Feature Engineering
Hello,
My research involves feature engineering signals. I am wondering if anyone can point me in the right direction for using/designing filters to generate features for classification and regression analyses of signals. I found a good source video about using the peaks of filters. However, it is a shot in the dark for me to develop the right filter. Let me know if anyone can point me in the right direction.
LukeHello,
My research involves feature engineering signals. I am wondering if anyone can point me in the right direction for using/designing filters to generate features for classification and regression analyses of signals. I found a good source video about using the peaks of filters. However, it is a shot in the dark for me to develop the right filter. Let me know if anyone can point me in the right direction.
Luke Hello,
My research involves feature engineering signals. I am wondering if anyone can point me in the right direction for using/designing filters to generate features for classification and regression analyses of signals. I found a good source video about using the peaks of filters. However, it is a shot in the dark for me to develop the right filter. Let me know if anyone can point me in the right direction.
Luke signal processing, feature extraction, filter design MATLAB Answers — New Questions
diff not working on a vector of values
Is there a reason why I cant calculate the difference between each of these values (x1)
This is the code Im using
[x1,y1]=SpotFind_NXC(app,ax2); %my function to locate x,y coordinates of spots in an image
x1
class(x1)
xdiff=abs(diff(x1))
and the command window:
x1 =
98.00
97.68
97.75
98.32
221.00
220.99
221.32
221.32
344.00
343.99
344.33
344.25
ans =
‘double’
Unrecognized function or variable ‘diff’.
2nd Question, once it works, how can I group these into "similar values". so ideally I would want the median (or mean) of the 1st group (98.00, 97.68. 97.75, 98.32), and then the median of the 2s group around 221 and the 3rd group around 344.
Thanks
JasonIs there a reason why I cant calculate the difference between each of these values (x1)
This is the code Im using
[x1,y1]=SpotFind_NXC(app,ax2); %my function to locate x,y coordinates of spots in an image
x1
class(x1)
xdiff=abs(diff(x1))
and the command window:
x1 =
98.00
97.68
97.75
98.32
221.00
220.99
221.32
221.32
344.00
343.99
344.33
344.25
ans =
‘double’
Unrecognized function or variable ‘diff’.
2nd Question, once it works, how can I group these into "similar values". so ideally I would want the median (or mean) of the 1st group (98.00, 97.68. 97.75, 98.32), and then the median of the 2s group around 221 and the 3rd group around 344.
Thanks
Jason Is there a reason why I cant calculate the difference between each of these values (x1)
This is the code Im using
[x1,y1]=SpotFind_NXC(app,ax2); %my function to locate x,y coordinates of spots in an image
x1
class(x1)
xdiff=abs(diff(x1))
and the command window:
x1 =
98.00
97.68
97.75
98.32
221.00
220.99
221.32
221.32
344.00
343.99
344.33
344.25
ans =
‘double’
Unrecognized function or variable ‘diff’.
2nd Question, once it works, how can I group these into "similar values". so ideally I would want the median (or mean) of the 1st group (98.00, 97.68. 97.75, 98.32), and then the median of the 2s group around 221 and the 3rd group around 344.
Thanks
Jason diff MATLAB Answers — New Questions
How to subscribe to multiple BLE characteristics that have the same service and characteristic UUID
I am trying to figure out how to subscribe to multiple temperature sensors from a BLE device. My goal is to read all 8 temperature sensors at 1Hz. The BLE device has an environmental sensing service, here are what it’s characteristics look like.
"ServiceName" "ServiceUUID" "CharacteristicName" "CharacteristicUUID" "Attributes"
"Generic Attribute" "1801" "Service Changed" "2A05" "Indicate"
"Generic Attribute" "1801" "Custom" "2B29" 1×2 string
"Generic Attribute" "1801" "Custom" "2B2A" "Read"
"Generic Access" "1800" "Device Name" "2A00" "Read"
"Generic Access" "1800" "Appearance" "2A01" "Read"
"Generic Access" "1800" "Peripheral Preferred Connection Parameters" "2A04" "Read"
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
The 1×2 string is
"Read" "Notify"
The line that I am using works when there is one temperature sensor but not when there are multiple. The line is
characteristic(sensor, "Environmental Sensing", "Temperature")
When I call this line when there are multiple sensors present I get the following error Failed to discover descriptors. If device is disconnected, then clear existing ble object and recreate it. The BLE device is a nRF52 based chip that I wrote the code for with Zephyr. If there is something wrong with how I made the GATT then I can go fix it to work with Matlab better. The descriptors have a characteristic user data field that gives a name for each temperature sensor as Sensor X where X is 0-7. I have confirmed hat the device is not the issue and is programmed correctly by testing it nRF connect.
Update:
Stepping through the code I found the error coming from how the ble message is being given to the transport. It is passing a vector and not a scalar that it seems like it is expecting. For example in Characteristic.m line 315,
methods(Access = {?matlabshared.blelib.Descriptor, ?matlabshared.blelib.read.characteristic.Interface, ?matlabshared.blelib.write.characteristic.Interface})
function output = execute(obj, cmd, varargin)
peripheral = obj.getParent;
% Supress warning that might be thrown in get.Connected
ws = warning(‘off’, ‘MATLAB:ble:ble:deviceDisconnected’);
c = onCleanup(@() cleanup(ws));
if ~peripheral.Connected
matlabshared.blelib.internal.localizedError(‘MATLAB:ble:ble:failToExecuteDeviceDisconnected’);
end
output = peripheral.execute(cmd, obj.ServiceIndex, obj.CharacteristicIndex, varargin{:});
function cleanup(ws)
warning(ws.state, ‘MATLAB:ble:ble:deviceDisconnected’);
end
end
end
For the line
output = peripheral.execute(cmd, obj.ServiceIndex, obj.CharacteristicIndex, varargin{:});
the arguments are
cmd = DISCOVER_DESCRIPTORS
obj.ServiceIndex = 3
obj.CharacteristicIndex = [1;2;3;4;5;6;7;8]
It seems like obj.CharacteristicIndex should be just a number to get it to work.
It seems like the source of the issue starts in ble.m line 411 when
cinfo.Index = find(subtable.CharacteristicUUID == uuid);
returns a column vector instead of a scalar
function cinfo = validateCharacteristic(obj, sinfo, input)
% Check if input is a valid characteristic name or UUID supported
% on the peripheral and return index of the characteristic for
% the specified service
% Validate data type
info = matlabshared.blelib.internal.ServicesCharacteristicsDescriptorsInfo.getInstance;
uuid = info.getCharacteristicUUID(sinfo.UUID, input);
uuid = info.getShortestUUID(uuid);
% Find portion of the table that has the same ServiceUUID
subtable = obj.Characteristics(obj.Characteristics.ServiceUUID == obj.Services.ServiceUUID(sinfo.Index), :);
try
uuid = validatestring(uuid, subtable.CharacteristicUUID);
catch e
if strcmpi(e.identifier,’MATLAB:ambiguousStringChoice’)
throwAsCaller(e);
else
matlabshared.blelib.internal.localizedError(‘MATLAB:ble:ble:unsupportedCharacteristic’);
end
end
cinfo = info.getCharacteristicInfoByUUID(sinfo.UUID, uuid);
cinfo.Index = find(subtable.CharacteristicUUID == uuid);
cinfo.Attributes = subtable.Attributes{cinfo.Index};
end
end
It looks like edits to the files are locked so I can’t quite write a new version of the functions to try and handle the case of multiple entries.I am trying to figure out how to subscribe to multiple temperature sensors from a BLE device. My goal is to read all 8 temperature sensors at 1Hz. The BLE device has an environmental sensing service, here are what it’s characteristics look like.
"ServiceName" "ServiceUUID" "CharacteristicName" "CharacteristicUUID" "Attributes"
"Generic Attribute" "1801" "Service Changed" "2A05" "Indicate"
"Generic Attribute" "1801" "Custom" "2B29" 1×2 string
"Generic Attribute" "1801" "Custom" "2B2A" "Read"
"Generic Access" "1800" "Device Name" "2A00" "Read"
"Generic Access" "1800" "Appearance" "2A01" "Read"
"Generic Access" "1800" "Peripheral Preferred Connection Parameters" "2A04" "Read"
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
The 1×2 string is
"Read" "Notify"
The line that I am using works when there is one temperature sensor but not when there are multiple. The line is
characteristic(sensor, "Environmental Sensing", "Temperature")
When I call this line when there are multiple sensors present I get the following error Failed to discover descriptors. If device is disconnected, then clear existing ble object and recreate it. The BLE device is a nRF52 based chip that I wrote the code for with Zephyr. If there is something wrong with how I made the GATT then I can go fix it to work with Matlab better. The descriptors have a characteristic user data field that gives a name for each temperature sensor as Sensor X where X is 0-7. I have confirmed hat the device is not the issue and is programmed correctly by testing it nRF connect.
Update:
Stepping through the code I found the error coming from how the ble message is being given to the transport. It is passing a vector and not a scalar that it seems like it is expecting. For example in Characteristic.m line 315,
methods(Access = {?matlabshared.blelib.Descriptor, ?matlabshared.blelib.read.characteristic.Interface, ?matlabshared.blelib.write.characteristic.Interface})
function output = execute(obj, cmd, varargin)
peripheral = obj.getParent;
% Supress warning that might be thrown in get.Connected
ws = warning(‘off’, ‘MATLAB:ble:ble:deviceDisconnected’);
c = onCleanup(@() cleanup(ws));
if ~peripheral.Connected
matlabshared.blelib.internal.localizedError(‘MATLAB:ble:ble:failToExecuteDeviceDisconnected’);
end
output = peripheral.execute(cmd, obj.ServiceIndex, obj.CharacteristicIndex, varargin{:});
function cleanup(ws)
warning(ws.state, ‘MATLAB:ble:ble:deviceDisconnected’);
end
end
end
For the line
output = peripheral.execute(cmd, obj.ServiceIndex, obj.CharacteristicIndex, varargin{:});
the arguments are
cmd = DISCOVER_DESCRIPTORS
obj.ServiceIndex = 3
obj.CharacteristicIndex = [1;2;3;4;5;6;7;8]
It seems like obj.CharacteristicIndex should be just a number to get it to work.
It seems like the source of the issue starts in ble.m line 411 when
cinfo.Index = find(subtable.CharacteristicUUID == uuid);
returns a column vector instead of a scalar
function cinfo = validateCharacteristic(obj, sinfo, input)
% Check if input is a valid characteristic name or UUID supported
% on the peripheral and return index of the characteristic for
% the specified service
% Validate data type
info = matlabshared.blelib.internal.ServicesCharacteristicsDescriptorsInfo.getInstance;
uuid = info.getCharacteristicUUID(sinfo.UUID, input);
uuid = info.getShortestUUID(uuid);
% Find portion of the table that has the same ServiceUUID
subtable = obj.Characteristics(obj.Characteristics.ServiceUUID == obj.Services.ServiceUUID(sinfo.Index), :);
try
uuid = validatestring(uuid, subtable.CharacteristicUUID);
catch e
if strcmpi(e.identifier,’MATLAB:ambiguousStringChoice’)
throwAsCaller(e);
else
matlabshared.blelib.internal.localizedError(‘MATLAB:ble:ble:unsupportedCharacteristic’);
end
end
cinfo = info.getCharacteristicInfoByUUID(sinfo.UUID, uuid);
cinfo.Index = find(subtable.CharacteristicUUID == uuid);
cinfo.Attributes = subtable.Attributes{cinfo.Index};
end
end
It looks like edits to the files are locked so I can’t quite write a new version of the functions to try and handle the case of multiple entries. I am trying to figure out how to subscribe to multiple temperature sensors from a BLE device. My goal is to read all 8 temperature sensors at 1Hz. The BLE device has an environmental sensing service, here are what it’s characteristics look like.
"ServiceName" "ServiceUUID" "CharacteristicName" "CharacteristicUUID" "Attributes"
"Generic Attribute" "1801" "Service Changed" "2A05" "Indicate"
"Generic Attribute" "1801" "Custom" "2B29" 1×2 string
"Generic Attribute" "1801" "Custom" "2B2A" "Read"
"Generic Access" "1800" "Device Name" "2A00" "Read"
"Generic Access" "1800" "Appearance" "2A01" "Read"
"Generic Access" "1800" "Peripheral Preferred Connection Parameters" "2A04" "Read"
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Temperature" "2A6E" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
"Environmental Sensing" "181A" "Humidity" "2A6F" 1×2 string
The 1×2 string is
"Read" "Notify"
The line that I am using works when there is one temperature sensor but not when there are multiple. The line is
characteristic(sensor, "Environmental Sensing", "Temperature")
When I call this line when there are multiple sensors present I get the following error Failed to discover descriptors. If device is disconnected, then clear existing ble object and recreate it. The BLE device is a nRF52 based chip that I wrote the code for with Zephyr. If there is something wrong with how I made the GATT then I can go fix it to work with Matlab better. The descriptors have a characteristic user data field that gives a name for each temperature sensor as Sensor X where X is 0-7. I have confirmed hat the device is not the issue and is programmed correctly by testing it nRF connect.
Update:
Stepping through the code I found the error coming from how the ble message is being given to the transport. It is passing a vector and not a scalar that it seems like it is expecting. For example in Characteristic.m line 315,
methods(Access = {?matlabshared.blelib.Descriptor, ?matlabshared.blelib.read.characteristic.Interface, ?matlabshared.blelib.write.characteristic.Interface})
function output = execute(obj, cmd, varargin)
peripheral = obj.getParent;
% Supress warning that might be thrown in get.Connected
ws = warning(‘off’, ‘MATLAB:ble:ble:deviceDisconnected’);
c = onCleanup(@() cleanup(ws));
if ~peripheral.Connected
matlabshared.blelib.internal.localizedError(‘MATLAB:ble:ble:failToExecuteDeviceDisconnected’);
end
output = peripheral.execute(cmd, obj.ServiceIndex, obj.CharacteristicIndex, varargin{:});
function cleanup(ws)
warning(ws.state, ‘MATLAB:ble:ble:deviceDisconnected’);
end
end
end
For the line
output = peripheral.execute(cmd, obj.ServiceIndex, obj.CharacteristicIndex, varargin{:});
the arguments are
cmd = DISCOVER_DESCRIPTORS
obj.ServiceIndex = 3
obj.CharacteristicIndex = [1;2;3;4;5;6;7;8]
It seems like obj.CharacteristicIndex should be just a number to get it to work.
It seems like the source of the issue starts in ble.m line 411 when
cinfo.Index = find(subtable.CharacteristicUUID == uuid);
returns a column vector instead of a scalar
function cinfo = validateCharacteristic(obj, sinfo, input)
% Check if input is a valid characteristic name or UUID supported
% on the peripheral and return index of the characteristic for
% the specified service
% Validate data type
info = matlabshared.blelib.internal.ServicesCharacteristicsDescriptorsInfo.getInstance;
uuid = info.getCharacteristicUUID(sinfo.UUID, input);
uuid = info.getShortestUUID(uuid);
% Find portion of the table that has the same ServiceUUID
subtable = obj.Characteristics(obj.Characteristics.ServiceUUID == obj.Services.ServiceUUID(sinfo.Index), :);
try
uuid = validatestring(uuid, subtable.CharacteristicUUID);
catch e
if strcmpi(e.identifier,’MATLAB:ambiguousStringChoice’)
throwAsCaller(e);
else
matlabshared.blelib.internal.localizedError(‘MATLAB:ble:ble:unsupportedCharacteristic’);
end
end
cinfo = info.getCharacteristicInfoByUUID(sinfo.UUID, uuid);
cinfo.Index = find(subtable.CharacteristicUUID == uuid);
cinfo.Attributes = subtable.Attributes{cinfo.Index};
end
end
It looks like edits to the files are locked so I can’t quite write a new version of the functions to try and handle the case of multiple entries. bluetooth, ble, identical characteristics, subscriptions MATLAB Answers — New Questions
Root locus with two inputs?
Hello,
I have a simulink model with two inputs, and I’m trying to get the root locus plot of it. Is this possible?
Thank you.Hello,
I have a simulink model with two inputs, and I’m trying to get the root locus plot of it. Is this possible?
Thank you. Hello,
I have a simulink model with two inputs, and I’m trying to get the root locus plot of it. Is this possible?
Thank you. simulink, input, transfer function MATLAB Answers — New Questions
How to Retreive All Time Data
When I run my simulink model, I generate a table in the workspace in a script that is run after simulation. This script gets the time from the output of the simulation as Time=out.tout. I can also get the data by exporting it from the simulation data inspector. When I use the simulation data inspector I get more time points that I do when I use the out.tout data method.
I would like to get the data in the simulation output to use when I generate the table in the workspace as it has more data of interest on and around some step changes in the simulation. How do I get non-truncated data without saving from the simulation data inspector? I would like to automate this and get it in workspace as the simulation will run many times and I use the workspace table to generate charts for each trial run.When I run my simulink model, I generate a table in the workspace in a script that is run after simulation. This script gets the time from the output of the simulation as Time=out.tout. I can also get the data by exporting it from the simulation data inspector. When I use the simulation data inspector I get more time points that I do when I use the out.tout data method.
I would like to get the data in the simulation output to use when I generate the table in the workspace as it has more data of interest on and around some step changes in the simulation. How do I get non-truncated data without saving from the simulation data inspector? I would like to automate this and get it in workspace as the simulation will run many times and I use the workspace table to generate charts for each trial run. When I run my simulink model, I generate a table in the workspace in a script that is run after simulation. This script gets the time from the output of the simulation as Time=out.tout. I can also get the data by exporting it from the simulation data inspector. When I use the simulation data inspector I get more time points that I do when I use the out.tout data method.
I would like to get the data in the simulation output to use when I generate the table in the workspace as it has more data of interest on and around some step changes in the simulation. How do I get non-truncated data without saving from the simulation data inspector? I would like to automate this and get it in workspace as the simulation will run many times and I use the workspace table to generate charts for each trial run. simulink, time, data, simulink data inspector, for loop MATLAB Answers — New Questions
Traitement d’image Cheminée Industrielle
Hello,
if anyone can help me on this subject
I’m at engineering school and I’m working on a project where we have to determine the condition of an industrial chimney (presence of rust/cracks). To do this, we capture the chimney and then process the image to determine whether the section photographed has any defects. I tried a first code with different tools:
-Contour detection with Canny Edge
-Segmentation using Thresholding
-Morphological analysis
I didn’t have much success, as some of the photos show welds, but it only detects welds and not cracks.
I’ve started looking into CNNs but I don’t know if it’s necessary.
I enclose a photo of the chimney
Thanks in advanceHello,
if anyone can help me on this subject
I’m at engineering school and I’m working on a project where we have to determine the condition of an industrial chimney (presence of rust/cracks). To do this, we capture the chimney and then process the image to determine whether the section photographed has any defects. I tried a first code with different tools:
-Contour detection with Canny Edge
-Segmentation using Thresholding
-Morphological analysis
I didn’t have much success, as some of the photos show welds, but it only detects welds and not cracks.
I’ve started looking into CNNs but I don’t know if it’s necessary.
I enclose a photo of the chimney
Thanks in advance Hello,
if anyone can help me on this subject
I’m at engineering school and I’m working on a project where we have to determine the condition of an industrial chimney (presence of rust/cracks). To do this, we capture the chimney and then process the image to determine whether the section photographed has any defects. I tried a first code with different tools:
-Contour detection with Canny Edge
-Segmentation using Thresholding
-Morphological analysis
I didn’t have much success, as some of the photos show welds, but it only detects welds and not cracks.
I’ve started looking into CNNs but I don’t know if it’s necessary.
I enclose a photo of the chimney
Thanks in advance transferred MATLAB Answers — New Questions
Problem with Casadi 3.6.5 installation on Matlab r2023b on Mac ARM64
Tried running below code to test Casadi in Matlab.
import casadi.*
x = MX.sym(‘x’)
disp(jacobian(sin(x),x))
Im getting the below error
Unrecognized function or variable ‘casadiMEX’.
Error in casadi.GenMX.sym (line 833)
[varargout{1:nargout}] = casadiMEX(356, varargin{:});Tried running below code to test Casadi in Matlab.
import casadi.*
x = MX.sym(‘x’)
disp(jacobian(sin(x),x))
Im getting the below error
Unrecognized function or variable ‘casadiMEX’.
Error in casadi.GenMX.sym (line 833)
[varargout{1:nargout}] = casadiMEX(356, varargin{:}); Tried running below code to test Casadi in Matlab.
import casadi.*
x = MX.sym(‘x’)
disp(jacobian(sin(x),x))
Im getting the below error
Unrecognized function or variable ‘casadiMEX’.
Error in casadi.GenMX.sym (line 833)
[varargout{1:nargout}] = casadiMEX(356, varargin{:}); casadi, arm64, r2023b MATLAB Answers — New Questions
Generate a time series from power spectral density
I have a force PSD of 2X2X63 acting at 2 points of 63 frequencies defined. For each frequency, there is a 2×2 matrix representing the auto and cross variances of the force. I want to construct a time signal of 2xN size where N is the size of the time signal. How do I do it?I have a force PSD of 2X2X63 acting at 2 points of 63 frequencies defined. For each frequency, there is a 2×2 matrix representing the auto and cross variances of the force. I want to construct a time signal of 2xN size where N is the size of the time signal. How do I do it? I have a force PSD of 2X2X63 acting at 2 points of 63 frequencies defined. For each frequency, there is a 2×2 matrix representing the auto and cross variances of the force. I want to construct a time signal of 2xN size where N is the size of the time signal. How do I do it? psd, fft, ifft MATLAB Answers — New Questions
A moving point plot in MATLAB figure with animation.
My program calculates position of a point on Z plane as (X,Y). I need to plot (X,Y) in Z-plane with a moving point showing location of point over the time in a single MATLAB figure. Please help.My program calculates position of a point on Z plane as (X,Y). I need to plot (X,Y) in Z-plane with a moving point showing location of point over the time in a single MATLAB figure. Please help. My program calculates position of a point on Z plane as (X,Y). I need to plot (X,Y) in Z-plane with a moving point showing location of point over the time in a single MATLAB figure. Please help. plot, animation MATLAB Answers — New Questions
Does Embedded Coder support Infineon Aurix Devices?
Hi There,
I am heading System Applications Team at Infineon India.
Some of our customers are keen to have MATLAB support for our Aurix Microcontrollers.
Would like to know what support is currently available & what are the options?
Thanks,
AvinashHi There,
I am heading System Applications Team at Infineon India.
Some of our customers are keen to have MATLAB support for our Aurix Microcontrollers.
Would like to know what support is currently available & what are the options?
Thanks,
Avinash Hi There,
I am heading System Applications Team at Infineon India.
Some of our customers are keen to have MATLAB support for our Aurix Microcontrollers.
Would like to know what support is currently available & what are the options?
Thanks,
Avinash infineon, aurix MATLAB Answers — New Questions
Problem 56313. Find Air Temperature from Cricket Stridulation Rate
function y = getTemperature_F(nchirps_in_14s)
x=[20 30 40 50]
F=0;
y=x;
y=fliplr(y);
while F<=50
F=F+110;
y=F-y;
end
end
%whats wrong with my answer i am not getting it.function y = getTemperature_F(nchirps_in_14s)
x=[20 30 40 50]
F=0;
y=x;
y=fliplr(y);
while F<=50
F=F+110;
y=F-y;
end
end
%whats wrong with my answer i am not getting it. function y = getTemperature_F(nchirps_in_14s)
x=[20 30 40 50]
F=0;
y=x;
y=fliplr(y);
while F<=50
F=F+110;
y=F-y;
end
end
%whats wrong with my answer i am not getting it. homework MATLAB Answers — New Questions
how to ask to the user to insert a command while a function is being executing?
In a previous version of my code, I implemented a function which reads data from serial port. While the function was storing and managing data received through the serial port, the user can each time insert a command "stop" which advice the connected device to stop the communication. The code was this:
configureCallback(controller,"byte",1,@readData)
%%
val = input(‘Comando: ‘,’s’);
% command start
writeline(controller, val);
%%
val = input(‘Comando: ‘,’s’);
% command stop
writeline(controller, val);
I’m trying to do the same but with my peripheral connected to my pc through bluetooth low energy.
However, I don’t know how to make the funcion works and the script asking for the command simultaneously, it seems like configureCallback function is not working in this case.
%% write START
val = input(‘Comando: ‘,’s’);
% Convert string to uint8 array
val_bytes = uint8(val);
% command start
write(c_write,val_bytes,’WithoutResponse’);
%% read data
if finished==0
% Set the callback function for the characteristic
c_read.DataAvailableFcn = @bleDataReceived;
end
%% write STOP
val = input(‘Comando: ‘,’s’);
% Convert string to uint8 array
val_bytes = uint8(val);
% command start
write(c_write,val_bytes,’WithoutResponse’);
i wrote this, but the function is continuosly reading after command start is sent without letting me the chance to insert the command stop.In a previous version of my code, I implemented a function which reads data from serial port. While the function was storing and managing data received through the serial port, the user can each time insert a command "stop" which advice the connected device to stop the communication. The code was this:
configureCallback(controller,"byte",1,@readData)
%%
val = input(‘Comando: ‘,’s’);
% command start
writeline(controller, val);
%%
val = input(‘Comando: ‘,’s’);
% command stop
writeline(controller, val);
I’m trying to do the same but with my peripheral connected to my pc through bluetooth low energy.
However, I don’t know how to make the funcion works and the script asking for the command simultaneously, it seems like configureCallback function is not working in this case.
%% write START
val = input(‘Comando: ‘,’s’);
% Convert string to uint8 array
val_bytes = uint8(val);
% command start
write(c_write,val_bytes,’WithoutResponse’);
%% read data
if finished==0
% Set the callback function for the characteristic
c_read.DataAvailableFcn = @bleDataReceived;
end
%% write STOP
val = input(‘Comando: ‘,’s’);
% Convert string to uint8 array
val_bytes = uint8(val);
% command start
write(c_write,val_bytes,’WithoutResponse’);
i wrote this, but the function is continuosly reading after command start is sent without letting me the chance to insert the command stop. In a previous version of my code, I implemented a function which reads data from serial port. While the function was storing and managing data received through the serial port, the user can each time insert a command "stop" which advice the connected device to stop the communication. The code was this:
configureCallback(controller,"byte",1,@readData)
%%
val = input(‘Comando: ‘,’s’);
% command start
writeline(controller, val);
%%
val = input(‘Comando: ‘,’s’);
% command stop
writeline(controller, val);
I’m trying to do the same but with my peripheral connected to my pc through bluetooth low energy.
However, I don’t know how to make the funcion works and the script asking for the command simultaneously, it seems like configureCallback function is not working in this case.
%% write START
val = input(‘Comando: ‘,’s’);
% Convert string to uint8 array
val_bytes = uint8(val);
% command start
write(c_write,val_bytes,’WithoutResponse’);
%% read data
if finished==0
% Set the callback function for the characteristic
c_read.DataAvailableFcn = @bleDataReceived;
end
%% write STOP
val = input(‘Comando: ‘,’s’);
% Convert string to uint8 array
val_bytes = uint8(val);
% command start
write(c_write,val_bytes,’WithoutResponse’);
i wrote this, but the function is continuosly reading after command start is sent without letting me the chance to insert the command stop. matlab, functions, function, callback, ble, bluetooth MATLAB Answers — New Questions
Extract certain values in .mat file
Hi,
I have a mat file with 1250×1 data and I want to extract specific values from the 1250. For example I want to extract every 2nd or every 5th values.
As an example, the mat file contains the following values:
-0.13793 -0.114746 -0.204773 -0.224304 -0.181274 -0.192566 -0.159912 -0.174866 -0.134888 -0.148926
For every 2nd I want to read: -0.114746 -0.224304 -0.192566 -0.174866 -0.148926
For every 5th I want to read: -0.181274 -0.148926
What is the best command to do this? Thank you.Hi,
I have a mat file with 1250×1 data and I want to extract specific values from the 1250. For example I want to extract every 2nd or every 5th values.
As an example, the mat file contains the following values:
-0.13793 -0.114746 -0.204773 -0.224304 -0.181274 -0.192566 -0.159912 -0.174866 -0.134888 -0.148926
For every 2nd I want to read: -0.114746 -0.224304 -0.192566 -0.174866 -0.148926
For every 5th I want to read: -0.181274 -0.148926
What is the best command to do this? Thank you. Hi,
I have a mat file with 1250×1 data and I want to extract specific values from the 1250. For example I want to extract every 2nd or every 5th values.
As an example, the mat file contains the following values:
-0.13793 -0.114746 -0.204773 -0.224304 -0.181274 -0.192566 -0.159912 -0.174866 -0.134888 -0.148926
For every 2nd I want to read: -0.114746 -0.224304 -0.192566 -0.174866 -0.148926
For every 5th I want to read: -0.181274 -0.148926
What is the best command to do this? Thank you. extract data MATLAB Answers — New Questions
Function definitions are not permitted in this context.
help me
Function definitions are not permitted in this context.help me
Function definitions are not permitted in this context. help me
Function definitions are not permitted in this context. matlab, matlab 2014b MATLAB Answers — New Questions
Error when installing NCORR Program in MATLAB for DIC
Hello,
I want to use DIC in MATLAB. I tried to import/install NCORR program to MATLAB but I get these two errors (screeshots below) that I need help resolving.
The .cpp files in my PC (screenshot-top) does not appear the same as in the reference tutorial i was seeing (screenshot-bottom).
Can someone pls tell me how to fix it. Thankyou!Hello,
I want to use DIC in MATLAB. I tried to import/install NCORR program to MATLAB but I get these two errors (screeshots below) that I need help resolving.
The .cpp files in my PC (screenshot-top) does not appear the same as in the reference tutorial i was seeing (screenshot-bottom).
Can someone pls tell me how to fix it. Thankyou! Hello,
I want to use DIC in MATLAB. I tried to import/install NCORR program to MATLAB but I get these two errors (screeshots below) that I need help resolving.
The .cpp files in my PC (screenshot-top) does not appear the same as in the reference tutorial i was seeing (screenshot-bottom).
Can someone pls tell me how to fix it. Thankyou! ncorr, compiler MATLAB Answers — New Questions
Error using (function_name). Too many output arguments.
I’m having some issues with this code:
clear
clc
fluido = "aria"
i=0;
for temp = 15:0.1:1500
i=i+1;
temperatura(i)=temp;
vettore_cp(i)=calcolo_cp(temp, fluido);
end
plot(temperatura,vettore_cp,"b-")
title("grafico del calore specifico in funzione della temperatura")
xlabel("temperatura [°C]")
ylabel("calore specifico [J/kg*K]")
The program should plot a diagram using the function calcolo_cp that calculates the specific heat and uses as inputs the temperature of the fluid and what type of fluid we want to examinate ( in this case "aria", "air" in english).
The function calcolo_cp is in the same folder and seems to work fine, the code of this function is:
function calcolo_cp(T,fluido)
if strcmp(fluido, "aria")
indice_riga=1;
elseif strcmp(fluido, "gas")
indice_riga=2;
else
disp("ERRORE FLUIDO")
end
coeff=[1000.61 0.482759e-1 0.462906e-3 -0.454035e-6 0.129112e-9;
1013.71 0.641882e-1 0.452287e-3 -0.444350e-6 0.125765e-9];
for i = 1:5
elementi_cp(i) = coeff(indice_riga,i)*T^(i-1);
end
cp = sum(elementi_cp)
end
I’m here if you need more information about my code.
Thank you all.I’m having some issues with this code:
clear
clc
fluido = "aria"
i=0;
for temp = 15:0.1:1500
i=i+1;
temperatura(i)=temp;
vettore_cp(i)=calcolo_cp(temp, fluido);
end
plot(temperatura,vettore_cp,"b-")
title("grafico del calore specifico in funzione della temperatura")
xlabel("temperatura [°C]")
ylabel("calore specifico [J/kg*K]")
The program should plot a diagram using the function calcolo_cp that calculates the specific heat and uses as inputs the temperature of the fluid and what type of fluid we want to examinate ( in this case "aria", "air" in english).
The function calcolo_cp is in the same folder and seems to work fine, the code of this function is:
function calcolo_cp(T,fluido)
if strcmp(fluido, "aria")
indice_riga=1;
elseif strcmp(fluido, "gas")
indice_riga=2;
else
disp("ERRORE FLUIDO")
end
coeff=[1000.61 0.482759e-1 0.462906e-3 -0.454035e-6 0.129112e-9;
1013.71 0.641882e-1 0.452287e-3 -0.444350e-6 0.125765e-9];
for i = 1:5
elementi_cp(i) = coeff(indice_riga,i)*T^(i-1);
end
cp = sum(elementi_cp)
end
I’m here if you need more information about my code.
Thank you all. I’m having some issues with this code:
clear
clc
fluido = "aria"
i=0;
for temp = 15:0.1:1500
i=i+1;
temperatura(i)=temp;
vettore_cp(i)=calcolo_cp(temp, fluido);
end
plot(temperatura,vettore_cp,"b-")
title("grafico del calore specifico in funzione della temperatura")
xlabel("temperatura [°C]")
ylabel("calore specifico [J/kg*K]")
The program should plot a diagram using the function calcolo_cp that calculates the specific heat and uses as inputs the temperature of the fluid and what type of fluid we want to examinate ( in this case "aria", "air" in english).
The function calcolo_cp is in the same folder and seems to work fine, the code of this function is:
function calcolo_cp(T,fluido)
if strcmp(fluido, "aria")
indice_riga=1;
elseif strcmp(fluido, "gas")
indice_riga=2;
else
disp("ERRORE FLUIDO")
end
coeff=[1000.61 0.482759e-1 0.462906e-3 -0.454035e-6 0.129112e-9;
1013.71 0.641882e-1 0.452287e-3 -0.444350e-6 0.125765e-9];
for i = 1:5
elementi_cp(i) = coeff(indice_riga,i)*T^(i-1);
end
cp = sum(elementi_cp)
end
I’m here if you need more information about my code.
Thank you all. error function, plot, too many output arguments, too many inputs arguments MATLAB Answers — New Questions
How do I assign frequency values to the obtained fft values without plotting . I need to know the value of the peak at 16Hz for further calculations.
clear all
close all
clc
L=10;
n=1.45;
c=2.9979e8;
dt = 6e-12;
T=10*2*L*n/c;
t = (-T/2/dt:1:T/2/dt)*dt;
Nt=round(T/dt);
fsine = 1e9;
vsine = 1;
phi = vsine*sin(2*pi*fsine*t);
EL1t=1.274e7*exp(1i*phi);
FP=fft(phi);
fs=1/dt/Nt;
Fs=(-1/dt/2:fs:1/dt/2-1);
Z=plot(Fs,fftshift(abs(fft(EL1t))));
I need to know the value at 16GHz in the plot.clear all
close all
clc
L=10;
n=1.45;
c=2.9979e8;
dt = 6e-12;
T=10*2*L*n/c;
t = (-T/2/dt:1:T/2/dt)*dt;
Nt=round(T/dt);
fsine = 1e9;
vsine = 1;
phi = vsine*sin(2*pi*fsine*t);
EL1t=1.274e7*exp(1i*phi);
FP=fft(phi);
fs=1/dt/Nt;
Fs=(-1/dt/2:fs:1/dt/2-1);
Z=plot(Fs,fftshift(abs(fft(EL1t))));
I need to know the value at 16GHz in the plot. clear all
close all
clc
L=10;
n=1.45;
c=2.9979e8;
dt = 6e-12;
T=10*2*L*n/c;
t = (-T/2/dt:1:T/2/dt)*dt;
Nt=round(T/dt);
fsine = 1e9;
vsine = 1;
phi = vsine*sin(2*pi*fsine*t);
EL1t=1.274e7*exp(1i*phi);
FP=fft(phi);
fs=1/dt/Nt;
Fs=(-1/dt/2:fs:1/dt/2-1);
Z=plot(Fs,fftshift(abs(fft(EL1t))));
I need to know the value at 16GHz in the plot. fft, plot MATLAB Answers — New Questions
Using c language to call the dll file generated by matlab, there is an error when running
I use matlab to generate a matlab code dll file (including library files and header files), and then write a c program to call this dll file, but the following error:I use matlab to generate a matlab code dll file (including library files and header files), and then write a c program to call this dll file, but the following error: I use matlab to generate a matlab code dll file (including library files and header files), and then write a c program to call this dll file, but the following error: dll MATLAB Answers — New Questions
What caused this error message?
—————————————————————————————————————
% Define the input signal x[n]
n = 0:49;
x = (-1).^n .* (n >= 0);
% Define the length of the input signal
N = length(x);
% Initialize the output signal y[n]
y = zeros(1, N);
% Define the initial conditions
y_minus_1 = 4;
y_minus_2 = -2;
% Calculate the output y[n] using the difference equation
for n = 1:50
if n == 1
y(n) = x(n) + x(n – 1) – (1/4) * y_minus_1 + (1/8) * y_minus_2;
elseif n == 2
y(n) = x(n) + x(n – 1) – (1/4) * y(n – 1) + (1/8) * y_minus_1;
else
y(n) = x(n) + x(n – 1) – (1/4) * y(n – 1) + (1/8) * y(n – 2);
end
end
% Plot the output signal y[n]
stem(0:N-1, y);
grid on;
xlabel(‘n’);
ylabel(‘y[n]’);
title(‘Output of the System’);
——————————————————————————————————————–
Array index should be positive integer or logical value.
Error: HW2_2_59_c (18th line)
y(n) = x(n) + x(n – 1) – (1/4) * y_minus_1 + (1/8) * y_minus_2;—————————————————————————————————————
% Define the input signal x[n]
n = 0:49;
x = (-1).^n .* (n >= 0);
% Define the length of the input signal
N = length(x);
% Initialize the output signal y[n]
y = zeros(1, N);
% Define the initial conditions
y_minus_1 = 4;
y_minus_2 = -2;
% Calculate the output y[n] using the difference equation
for n = 1:50
if n == 1
y(n) = x(n) + x(n – 1) – (1/4) * y_minus_1 + (1/8) * y_minus_2;
elseif n == 2
y(n) = x(n) + x(n – 1) – (1/4) * y(n – 1) + (1/8) * y_minus_1;
else
y(n) = x(n) + x(n – 1) – (1/4) * y(n – 1) + (1/8) * y(n – 2);
end
end
% Plot the output signal y[n]
stem(0:N-1, y);
grid on;
xlabel(‘n’);
ylabel(‘y[n]’);
title(‘Output of the System’);
——————————————————————————————————————–
Array index should be positive integer or logical value.
Error: HW2_2_59_c (18th line)
y(n) = x(n) + x(n – 1) – (1/4) * y_minus_1 + (1/8) * y_minus_2; —————————————————————————————————————
% Define the input signal x[n]
n = 0:49;
x = (-1).^n .* (n >= 0);
% Define the length of the input signal
N = length(x);
% Initialize the output signal y[n]
y = zeros(1, N);
% Define the initial conditions
y_minus_1 = 4;
y_minus_2 = -2;
% Calculate the output y[n] using the difference equation
for n = 1:50
if n == 1
y(n) = x(n) + x(n – 1) – (1/4) * y_minus_1 + (1/8) * y_minus_2;
elseif n == 2
y(n) = x(n) + x(n – 1) – (1/4) * y(n – 1) + (1/8) * y_minus_1;
else
y(n) = x(n) + x(n – 1) – (1/4) * y(n – 1) + (1/8) * y(n – 2);
end
end
% Plot the output signal y[n]
stem(0:N-1, y);
grid on;
xlabel(‘n’);
ylabel(‘y[n]’);
title(‘Output of the System’);
——————————————————————————————————————–
Array index should be positive integer or logical value.
Error: HW2_2_59_c (18th line)
y(n) = x(n) + x(n – 1) – (1/4) * y_minus_1 + (1/8) * y_minus_2; #difference equation, #index error MATLAB Answers — New Questions