Category: Matlab
Category Archives: Matlab
What can I do to make the output characteristic of the network is two value, that is the implement multivariate input and multivariable output
I want to change the network structure to achieve that the predicted value of the output is two features. the net work is as follows link, but i can’t realize my idea. please help me, thank you very much. hope you have a nice day!
CNN-LSTM 时间序列预测 Matlab 单变量时间系列 – 文件交换 – MATLAB Central (mathworks.cn)I want to change the network structure to achieve that the predicted value of the output is two features. the net work is as follows link, but i can’t realize my idea. please help me, thank you very much. hope you have a nice day!
CNN-LSTM 时间序列预测 Matlab 单变量时间系列 – 文件交换 – MATLAB Central (mathworks.cn) I want to change the network structure to achieve that the predicted value of the output is two features. the net work is as follows link, but i can’t realize my idea. please help me, thank you very much. hope you have a nice day!
CNN-LSTM 时间序列预测 Matlab 单变量时间系列 – 文件交换 – MATLAB Central (mathworks.cn) neural network, cnn, lstm, signal predict, predict MATLAB Answers — New Questions
Spectrogram output versus figure
When using spectrogram to calculate power spectral density for a large dataset, the plot produced by directly running the command with no output arguments is slightly different from what I get when I run it with an output argument and plot that output myself.
For example, the following plots spectrograms for a subset of my data and compares the direct result of spectrogram with the output raster:
load(‘exampledata.mat’)
window = 10000;
noverlap = round(0.1*window);
fs = 10000;
figure(1);clf
t = tiledlayout(3,1, ‘TileIndexing’, ‘columnmajor’);
% Plot spectrogram directly from spectrogram function
s(1) = nexttile;
spectrogram(exampledata,window,noverlap,window,fs);
title(‘Original spectrogram plot (real data)’)
PSDdB_orig = get(get(gca,’Children’),’CData’);
caxis([min(PSDdB_orig,[],’all’) max(PSDdB_orig,[],’all’)])
% Calculate power spectral density and plot as decibels
[~,F,T,PSD] = spectrogram(exampledata,window,noverlap,window,fs);
PSDdB = (10.*log10(PSD))’;
s(2) = nexttile;
imagesc(F./1000,T./60,PSDdB)
title(‘Spectrogram output raster (real data)’)
c = colorbar;
caxis([min(PSDdB,[],’all’) max(PSDdB,[],’all’)])
set(get(c,’label’),’string’,’Power/frequency (dB/Hz)’,’Rotation’,90);
% Calculate ratio of the two approaches above and plot that
PSDdiff = PSDdB_orig./PSDdB;
s(3) = nexttile;
imagesc(F./1000,T./60,PSDdiff)
title(‘Original plot data divided by output raster data’)
c = colorbar;
caxis([min(PSDdiff,[],’all’) max(PSDdiff,[],’all’)])
set(get(c,’label’),’string’,’original/output’,’Rotation’,90);
set(s(2:3),’YDir’,’normal’)
xlabel(s(2:3), s(1).XLabel.String)
ylabel(s(2:3), s(1).YLabel.String)
From the figures above, it looks like they produce nearly the same result, except at high frequencies (the middle figure looks more different than the first mostly due to the different color scales).
Comparing the ranges and plotting a cross-section (example spectra at a single time) from each one shows that the difference seems to be that spectrogram’s direct plotting method is cutting off local minima:
disp([‘min/max of original spectrogram plot: ‘,num2str(min(PSDdB_orig,[],’all’)),’, ‘,num2str(max(PSDdB_orig,[],’all’))])
disp([‘min/max of spectrogram output raster: ‘,num2str(min(PSDdB,[],’all’)),’, ‘,num2str(max(PSDdB,[],’all’))])
% Plot example spectra from each approach
figure(2);clf
subplot(2,1,1);
plot(F./1000,PSDdB(10,:),F./1000,PSDdB_orig(10,:),’–‘);
legend(‘Spectrogram output raster’,’Original spectrogram’)
title(‘Example spectra’)
xlabel(‘Frequency (kHz)’)
ylabel(‘Power/frequency (dB/Hz)’)
% zoom in on high frequency range where values differ
subplot(2,1,2,copyobj(gca,gcf))
xlim([4.75 4.85])
title(‘high frequency close-up’)
But weirdly, I can’t reproduce this with randomly generated synthetic data:
x = randn(length(exampledata),1);
figure(3);clf
t = tiledlayout(3,1, ‘TileIndexing’, ‘columnmajor’);
s(1) = nexttile;
spectrogram(x,window,noverlap,window,fs);
title(‘Original spectrogram plot (synthetic data)’)
PSDdB_orig = get(get(gca,’Children’),’CData’);
caxis([min(PSDdB_orig,[],’all’) max(PSDdB_orig,[],’all’)])
[~,F,T,PSD] = spectrogram(x,window,noverlap,window,fs);
PSDdB = (10.*log10(PSD))’;
PSDdiff = PSDdB_orig./PSDdB;
s(2) = nexttile;
imagesc(F./1000,T./60,PSDdB)
title(‘Spectrogram output raster (synthetic data)’)
c = colorbar;
caxis([min(PSDdB,[],’all’) max(PSDdB,[],’all’)])
set(get(c,’label’),’string’,’Power/frequency (dB/Hz)’,’Rotation’,90);
s(3) = nexttile;
imagesc(F./1000,T./60,PSDdiff)
title(‘Original plot data divided by output raster data’)
c = colorbar;
caxis([min(PSDdiff,[],’all’) max(PSDdiff,[],’all’)])
set(get(c,’label’),’string’,’original/output’,’Rotation’,90);
set(s(2:3),’YDir’,’normal’)
xlabel(s(2:3), s(1).XLabel.String)
ylabel(s(2:3), s(1).YLabel.String)
disp([‘min/max of original spectrogram plot: ‘,num2str(min(PSDdB_orig,[],’all’)),’, ‘,num2str(max(PSDdB_orig,[],’all’))])
disp([‘min/max of spectrogram output raster: ‘,num2str(min(PSDdB,[],’all’)),’, ‘,num2str(max(PSDdB,[],’all’))])
I do notice that the minimum PSD value for my data (-196 dB) is significantly lower than the minimum of the synthetic data. Is there a lower limit where spectrogram starts to censor spectra (say, around -156.5351 dB)? Or is something else going on here? Any help would be much appreciated!! Thanks!When using spectrogram to calculate power spectral density for a large dataset, the plot produced by directly running the command with no output arguments is slightly different from what I get when I run it with an output argument and plot that output myself.
For example, the following plots spectrograms for a subset of my data and compares the direct result of spectrogram with the output raster:
load(‘exampledata.mat’)
window = 10000;
noverlap = round(0.1*window);
fs = 10000;
figure(1);clf
t = tiledlayout(3,1, ‘TileIndexing’, ‘columnmajor’);
% Plot spectrogram directly from spectrogram function
s(1) = nexttile;
spectrogram(exampledata,window,noverlap,window,fs);
title(‘Original spectrogram plot (real data)’)
PSDdB_orig = get(get(gca,’Children’),’CData’);
caxis([min(PSDdB_orig,[],’all’) max(PSDdB_orig,[],’all’)])
% Calculate power spectral density and plot as decibels
[~,F,T,PSD] = spectrogram(exampledata,window,noverlap,window,fs);
PSDdB = (10.*log10(PSD))’;
s(2) = nexttile;
imagesc(F./1000,T./60,PSDdB)
title(‘Spectrogram output raster (real data)’)
c = colorbar;
caxis([min(PSDdB,[],’all’) max(PSDdB,[],’all’)])
set(get(c,’label’),’string’,’Power/frequency (dB/Hz)’,’Rotation’,90);
% Calculate ratio of the two approaches above and plot that
PSDdiff = PSDdB_orig./PSDdB;
s(3) = nexttile;
imagesc(F./1000,T./60,PSDdiff)
title(‘Original plot data divided by output raster data’)
c = colorbar;
caxis([min(PSDdiff,[],’all’) max(PSDdiff,[],’all’)])
set(get(c,’label’),’string’,’original/output’,’Rotation’,90);
set(s(2:3),’YDir’,’normal’)
xlabel(s(2:3), s(1).XLabel.String)
ylabel(s(2:3), s(1).YLabel.String)
From the figures above, it looks like they produce nearly the same result, except at high frequencies (the middle figure looks more different than the first mostly due to the different color scales).
Comparing the ranges and plotting a cross-section (example spectra at a single time) from each one shows that the difference seems to be that spectrogram’s direct plotting method is cutting off local minima:
disp([‘min/max of original spectrogram plot: ‘,num2str(min(PSDdB_orig,[],’all’)),’, ‘,num2str(max(PSDdB_orig,[],’all’))])
disp([‘min/max of spectrogram output raster: ‘,num2str(min(PSDdB,[],’all’)),’, ‘,num2str(max(PSDdB,[],’all’))])
% Plot example spectra from each approach
figure(2);clf
subplot(2,1,1);
plot(F./1000,PSDdB(10,:),F./1000,PSDdB_orig(10,:),’–‘);
legend(‘Spectrogram output raster’,’Original spectrogram’)
title(‘Example spectra’)
xlabel(‘Frequency (kHz)’)
ylabel(‘Power/frequency (dB/Hz)’)
% zoom in on high frequency range where values differ
subplot(2,1,2,copyobj(gca,gcf))
xlim([4.75 4.85])
title(‘high frequency close-up’)
But weirdly, I can’t reproduce this with randomly generated synthetic data:
x = randn(length(exampledata),1);
figure(3);clf
t = tiledlayout(3,1, ‘TileIndexing’, ‘columnmajor’);
s(1) = nexttile;
spectrogram(x,window,noverlap,window,fs);
title(‘Original spectrogram plot (synthetic data)’)
PSDdB_orig = get(get(gca,’Children’),’CData’);
caxis([min(PSDdB_orig,[],’all’) max(PSDdB_orig,[],’all’)])
[~,F,T,PSD] = spectrogram(x,window,noverlap,window,fs);
PSDdB = (10.*log10(PSD))’;
PSDdiff = PSDdB_orig./PSDdB;
s(2) = nexttile;
imagesc(F./1000,T./60,PSDdB)
title(‘Spectrogram output raster (synthetic data)’)
c = colorbar;
caxis([min(PSDdB,[],’all’) max(PSDdB,[],’all’)])
set(get(c,’label’),’string’,’Power/frequency (dB/Hz)’,’Rotation’,90);
s(3) = nexttile;
imagesc(F./1000,T./60,PSDdiff)
title(‘Original plot data divided by output raster data’)
c = colorbar;
caxis([min(PSDdiff,[],’all’) max(PSDdiff,[],’all’)])
set(get(c,’label’),’string’,’original/output’,’Rotation’,90);
set(s(2:3),’YDir’,’normal’)
xlabel(s(2:3), s(1).XLabel.String)
ylabel(s(2:3), s(1).YLabel.String)
disp([‘min/max of original spectrogram plot: ‘,num2str(min(PSDdB_orig,[],’all’)),’, ‘,num2str(max(PSDdB_orig,[],’all’))])
disp([‘min/max of spectrogram output raster: ‘,num2str(min(PSDdB,[],’all’)),’, ‘,num2str(max(PSDdB,[],’all’))])
I do notice that the minimum PSD value for my data (-196 dB) is significantly lower than the minimum of the synthetic data. Is there a lower limit where spectrogram starts to censor spectra (say, around -156.5351 dB)? Or is something else going on here? Any help would be much appreciated!! Thanks! When using spectrogram to calculate power spectral density for a large dataset, the plot produced by directly running the command with no output arguments is slightly different from what I get when I run it with an output argument and plot that output myself.
For example, the following plots spectrograms for a subset of my data and compares the direct result of spectrogram with the output raster:
load(‘exampledata.mat’)
window = 10000;
noverlap = round(0.1*window);
fs = 10000;
figure(1);clf
t = tiledlayout(3,1, ‘TileIndexing’, ‘columnmajor’);
% Plot spectrogram directly from spectrogram function
s(1) = nexttile;
spectrogram(exampledata,window,noverlap,window,fs);
title(‘Original spectrogram plot (real data)’)
PSDdB_orig = get(get(gca,’Children’),’CData’);
caxis([min(PSDdB_orig,[],’all’) max(PSDdB_orig,[],’all’)])
% Calculate power spectral density and plot as decibels
[~,F,T,PSD] = spectrogram(exampledata,window,noverlap,window,fs);
PSDdB = (10.*log10(PSD))’;
s(2) = nexttile;
imagesc(F./1000,T./60,PSDdB)
title(‘Spectrogram output raster (real data)’)
c = colorbar;
caxis([min(PSDdB,[],’all’) max(PSDdB,[],’all’)])
set(get(c,’label’),’string’,’Power/frequency (dB/Hz)’,’Rotation’,90);
% Calculate ratio of the two approaches above and plot that
PSDdiff = PSDdB_orig./PSDdB;
s(3) = nexttile;
imagesc(F./1000,T./60,PSDdiff)
title(‘Original plot data divided by output raster data’)
c = colorbar;
caxis([min(PSDdiff,[],’all’) max(PSDdiff,[],’all’)])
set(get(c,’label’),’string’,’original/output’,’Rotation’,90);
set(s(2:3),’YDir’,’normal’)
xlabel(s(2:3), s(1).XLabel.String)
ylabel(s(2:3), s(1).YLabel.String)
From the figures above, it looks like they produce nearly the same result, except at high frequencies (the middle figure looks more different than the first mostly due to the different color scales).
Comparing the ranges and plotting a cross-section (example spectra at a single time) from each one shows that the difference seems to be that spectrogram’s direct plotting method is cutting off local minima:
disp([‘min/max of original spectrogram plot: ‘,num2str(min(PSDdB_orig,[],’all’)),’, ‘,num2str(max(PSDdB_orig,[],’all’))])
disp([‘min/max of spectrogram output raster: ‘,num2str(min(PSDdB,[],’all’)),’, ‘,num2str(max(PSDdB,[],’all’))])
% Plot example spectra from each approach
figure(2);clf
subplot(2,1,1);
plot(F./1000,PSDdB(10,:),F./1000,PSDdB_orig(10,:),’–‘);
legend(‘Spectrogram output raster’,’Original spectrogram’)
title(‘Example spectra’)
xlabel(‘Frequency (kHz)’)
ylabel(‘Power/frequency (dB/Hz)’)
% zoom in on high frequency range where values differ
subplot(2,1,2,copyobj(gca,gcf))
xlim([4.75 4.85])
title(‘high frequency close-up’)
But weirdly, I can’t reproduce this with randomly generated synthetic data:
x = randn(length(exampledata),1);
figure(3);clf
t = tiledlayout(3,1, ‘TileIndexing’, ‘columnmajor’);
s(1) = nexttile;
spectrogram(x,window,noverlap,window,fs);
title(‘Original spectrogram plot (synthetic data)’)
PSDdB_orig = get(get(gca,’Children’),’CData’);
caxis([min(PSDdB_orig,[],’all’) max(PSDdB_orig,[],’all’)])
[~,F,T,PSD] = spectrogram(x,window,noverlap,window,fs);
PSDdB = (10.*log10(PSD))’;
PSDdiff = PSDdB_orig./PSDdB;
s(2) = nexttile;
imagesc(F./1000,T./60,PSDdB)
title(‘Spectrogram output raster (synthetic data)’)
c = colorbar;
caxis([min(PSDdB,[],’all’) max(PSDdB,[],’all’)])
set(get(c,’label’),’string’,’Power/frequency (dB/Hz)’,’Rotation’,90);
s(3) = nexttile;
imagesc(F./1000,T./60,PSDdiff)
title(‘Original plot data divided by output raster data’)
c = colorbar;
caxis([min(PSDdiff,[],’all’) max(PSDdiff,[],’all’)])
set(get(c,’label’),’string’,’original/output’,’Rotation’,90);
set(s(2:3),’YDir’,’normal’)
xlabel(s(2:3), s(1).XLabel.String)
ylabel(s(2:3), s(1).YLabel.String)
disp([‘min/max of original spectrogram plot: ‘,num2str(min(PSDdB_orig,[],’all’)),’, ‘,num2str(max(PSDdB_orig,[],’all’))])
disp([‘min/max of spectrogram output raster: ‘,num2str(min(PSDdB,[],’all’)),’, ‘,num2str(max(PSDdB,[],’all’))])
I do notice that the minimum PSD value for my data (-196 dB) is significantly lower than the minimum of the synthetic data. Is there a lower limit where spectrogram starts to censor spectra (say, around -156.5351 dB)? Or is something else going on here? Any help would be much appreciated!! Thanks! spectrogram, spectral analysis, signal processing MATLAB Answers — New Questions
extracting overlapping portions of 2 similar tracks
hi and thanks in advance
I have cyclone tracks extracted from 2 different sources labeled as trackBom and trackRe (stored in sampleTracks.mat). I am trying to bias-correct some variables along these tracks. To do that, I need to extract the overlapping portions of the tracks. The issue is that these tracks do not exactly align in space or time. I have attached a figure showing the original tracks and the overlapping portions that I want to extract. What i want is to extract the overlapping (or almost overlapping) portions of the tracks as shown in the picture and store them as trackBomLap and trackReLap to impliment my bias correction metods.
your help is much appreciated.hi and thanks in advance
I have cyclone tracks extracted from 2 different sources labeled as trackBom and trackRe (stored in sampleTracks.mat). I am trying to bias-correct some variables along these tracks. To do that, I need to extract the overlapping portions of the tracks. The issue is that these tracks do not exactly align in space or time. I have attached a figure showing the original tracks and the overlapping portions that I want to extract. What i want is to extract the overlapping (or almost overlapping) portions of the tracks as shown in the picture and store them as trackBomLap and trackReLap to impliment my bias correction metods.
your help is much appreciated. hi and thanks in advance
I have cyclone tracks extracted from 2 different sources labeled as trackBom and trackRe (stored in sampleTracks.mat). I am trying to bias-correct some variables along these tracks. To do that, I need to extract the overlapping portions of the tracks. The issue is that these tracks do not exactly align in space or time. I have attached a figure showing the original tracks and the overlapping portions that I want to extract. What i want is to extract the overlapping (or almost overlapping) portions of the tracks as shown in the picture and store them as trackBomLap and trackReLap to impliment my bias correction metods.
your help is much appreciated. track matching MATLAB Answers — New Questions
Data is not storage when running loop
hello community
please help me to understand why data does not show when I run a loop:
I have 2 files: @Data01.mat and @Data05.mat I want to extrac data points when conditions are met’
if I run my script with Data1 all the parameters are there:
figure;plot (Epm_nEngallc0_4, IKCtl_au16_0allc, ‘.’);
but if I run my script with Data1&2 the output is different and I get less data points
I would expect to have all data poins from @Data01.mat plus @Data05.mat
please help me to see what am I doing wrong.
clear all; %
clc; %
fprintf(‘select folder containing data filesn’);
currentpath=pwd; %%
datapath=uigetdir(”,’Select Data Folder’); %%
if (datapath == 0)
fprintf(‘Data directory was not selected…script will be terminatednn’);
return
end
prompt = ‘Do you want to export data as .xlsx?’;
save_data_excel = questdlg(prompt,’Save’,’Yes’,’No’,’Yes’);
cd(datapath); %%
files=dir(‘@*.mat’); %%
num_files=length(files(:,1)); %%
for i=1:num_files
fprintf(‘Progress: %d/%dnn’,i, num_files)
load(files(i,1).name)
idx = [false; diff(xzsen__ls_0_rs_) < 0];
idx1 = [false; diff(xzsen__ls_1_rs_) < 0];
idx2 = [false; diff(xzsen__ls_2_rs_) < 0];
idx3 = [false; diff(xzsen__ls_0_rs_) < 0];
idx4 = [false; diff(xzsen__ls_1_rs_) < 0];
idx5 = [false; diff(xzsen__ls_2_rs_) < 0];
for j=1:length(time)
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_1_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_3_rs_(j) > 0.165
Epm_nEngallc1_3(j,1) = Epm_nEng(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_2_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_5_rs_(j) > 0.165
Epm_nEngallc2_5(j,1) = Epm_nEng(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_0_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_4_rs_(j) > 0.165
Epm_nEngallc0_4(j,1) = Epm_nEng(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_1_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_3_rs_(j) > 0.165
IKCtl_au16_1allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_1_rs_(j);
IKCtl_au16_3allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_3_rs_(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_2_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_5_rs_(j) > 0.165
IKCtl_au16_2allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_2_rs_(j);
IKCtl_au16_5allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_5_rs_(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_0_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_4_rs_(j) > 0.165
IKCtl_au16_0allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_0_rs_(j);
IKCtl_au16_4allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_4_rs_(j);
end
end
endhello community
please help me to understand why data does not show when I run a loop:
I have 2 files: @Data01.mat and @Data05.mat I want to extrac data points when conditions are met’
if I run my script with Data1 all the parameters are there:
figure;plot (Epm_nEngallc0_4, IKCtl_au16_0allc, ‘.’);
but if I run my script with Data1&2 the output is different and I get less data points
I would expect to have all data poins from @Data01.mat plus @Data05.mat
please help me to see what am I doing wrong.
clear all; %
clc; %
fprintf(‘select folder containing data filesn’);
currentpath=pwd; %%
datapath=uigetdir(”,’Select Data Folder’); %%
if (datapath == 0)
fprintf(‘Data directory was not selected…script will be terminatednn’);
return
end
prompt = ‘Do you want to export data as .xlsx?’;
save_data_excel = questdlg(prompt,’Save’,’Yes’,’No’,’Yes’);
cd(datapath); %%
files=dir(‘@*.mat’); %%
num_files=length(files(:,1)); %%
for i=1:num_files
fprintf(‘Progress: %d/%dnn’,i, num_files)
load(files(i,1).name)
idx = [false; diff(xzsen__ls_0_rs_) < 0];
idx1 = [false; diff(xzsen__ls_1_rs_) < 0];
idx2 = [false; diff(xzsen__ls_2_rs_) < 0];
idx3 = [false; diff(xzsen__ls_0_rs_) < 0];
idx4 = [false; diff(xzsen__ls_1_rs_) < 0];
idx5 = [false; diff(xzsen__ls_2_rs_) < 0];
for j=1:length(time)
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_1_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_3_rs_(j) > 0.165
Epm_nEngallc1_3(j,1) = Epm_nEng(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_2_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_5_rs_(j) > 0.165
Epm_nEngallc2_5(j,1) = Epm_nEng(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_0_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_4_rs_(j) > 0.165
Epm_nEngallc0_4(j,1) = Epm_nEng(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_1_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_3_rs_(j) > 0.165
IKCtl_au16_1allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_1_rs_(j);
IKCtl_au16_3allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_3_rs_(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_2_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_5_rs_(j) > 0.165
IKCtl_au16_2allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_2_rs_(j);
IKCtl_au16_5allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_5_rs_(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_0_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_4_rs_(j) > 0.165
IKCtl_au16_0allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_0_rs_(j);
IKCtl_au16_4allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_4_rs_(j);
end
end
end hello community
please help me to understand why data does not show when I run a loop:
I have 2 files: @Data01.mat and @Data05.mat I want to extrac data points when conditions are met’
if I run my script with Data1 all the parameters are there:
figure;plot (Epm_nEngallc0_4, IKCtl_au16_0allc, ‘.’);
but if I run my script with Data1&2 the output is different and I get less data points
I would expect to have all data poins from @Data01.mat plus @Data05.mat
please help me to see what am I doing wrong.
clear all; %
clc; %
fprintf(‘select folder containing data filesn’);
currentpath=pwd; %%
datapath=uigetdir(”,’Select Data Folder’); %%
if (datapath == 0)
fprintf(‘Data directory was not selected…script will be terminatednn’);
return
end
prompt = ‘Do you want to export data as .xlsx?’;
save_data_excel = questdlg(prompt,’Save’,’Yes’,’No’,’Yes’);
cd(datapath); %%
files=dir(‘@*.mat’); %%
num_files=length(files(:,1)); %%
for i=1:num_files
fprintf(‘Progress: %d/%dnn’,i, num_files)
load(files(i,1).name)
idx = [false; diff(xzsen__ls_0_rs_) < 0];
idx1 = [false; diff(xzsen__ls_1_rs_) < 0];
idx2 = [false; diff(xzsen__ls_2_rs_) < 0];
idx3 = [false; diff(xzsen__ls_0_rs_) < 0];
idx4 = [false; diff(xzsen__ls_1_rs_) < 0];
idx5 = [false; diff(xzsen__ls_2_rs_) < 0];
for j=1:length(time)
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_1_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_3_rs_(j) > 0.165
Epm_nEngallc1_3(j,1) = Epm_nEng(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_2_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_5_rs_(j) > 0.165
Epm_nEngallc2_5(j,1) = Epm_nEng(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_0_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_4_rs_(j) > 0.165
Epm_nEngallc0_4(j,1) = Epm_nEng(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_1_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_3_rs_(j) > 0.165
IKCtl_au16_1allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_1_rs_(j);
IKCtl_au16_3allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_3_rs_(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_2_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_5_rs_(j) > 0.165
IKCtl_au16_2allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_2_rs_(j);
IKCtl_au16_5allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_5_rs_(j);
end
if Epm_nEng(j) > 0 && IKCtl_DiagRefLvlMinErr_au16__ls_0_rs_(j) > 0.165 && IKCtl_DiagRefLvlMinErr_au16__ls_4_rs_(j) > 0.165
IKCtl_au16_0allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_0_rs_(j);
IKCtl_au16_4allc(j,1)= IKCtl_DiagRefLvlMinErr_au16__ls_4_rs_(j);
end
end
end loops, matlab MATLAB Answers — New Questions
Calculation of psnr value in RGB image. I have calculated psnr using this code. But the result obtained is a complex number. What should be the error??
if true
function PSNR = psnrgb(I,W)
[m,n,p] = size(I);
[h,w,q] = size(W);
if m ~= h || n ~= w || p~=q
error(‘Two images must have the same size.’)
end
for k=1:p
for i=1:m
for j=1:n
delta=sum(I(i,j,k)-W(i,j,k).^2);
end
end
end
delta = 1/(m*n*p) * delta ;
PSNR = 10 * log10( 255^2/delta );
end
endif true
function PSNR = psnrgb(I,W)
[m,n,p] = size(I);
[h,w,q] = size(W);
if m ~= h || n ~= w || p~=q
error(‘Two images must have the same size.’)
end
for k=1:p
for i=1:m
for j=1:n
delta=sum(I(i,j,k)-W(i,j,k).^2);
end
end
end
delta = 1/(m*n*p) * delta ;
PSNR = 10 * log10( 255^2/delta );
end
end if true
function PSNR = psnrgb(I,W)
[m,n,p] = size(I);
[h,w,q] = size(W);
if m ~= h || n ~= w || p~=q
error(‘Two images must have the same size.’)
end
for k=1:p
for i=1:m
for j=1:n
delta=sum(I(i,j,k)-W(i,j,k).^2);
end
end
end
delta = 1/(m*n*p) * delta ;
PSNR = 10 * log10( 255^2/delta );
end
end image processing, steganography MATLAB Answers — New Questions
Trouble Plotting Basic Function
I’m having difficulty getting a function to plot correctly in Matlab. The function is:
f(x) = x^3 – sin(x) – e^x
I’ve tried using the below but the graph is not how it should appear:
X = -4:0.01:10;
Y = X.^3 – (sin(X)) – (exp(X));
plot(X,Y)I’m having difficulty getting a function to plot correctly in Matlab. The function is:
f(x) = x^3 – sin(x) – e^x
I’ve tried using the below but the graph is not how it should appear:
X = -4:0.01:10;
Y = X.^3 – (sin(X)) – (exp(X));
plot(X,Y) I’m having difficulty getting a function to plot correctly in Matlab. The function is:
f(x) = x^3 – sin(x) – e^x
I’ve tried using the below but the graph is not how it should appear:
X = -4:0.01:10;
Y = X.^3 – (sin(X)) – (exp(X));
plot(X,Y) plot, function MATLAB Answers — New Questions
Chasing what is wrong with ‘dual-simplex-highs’ in linprog
I try to see why ‘dual-simplex-highs’ algorithm fails and ‘dual-simplex-legacy’ works OK on this specific LP problem of size 467.
The linear programming involves only linear equality constraints, and lower bounds x >= 0 on some components of x (but not all of them).
The Aeq size is 211 x 467 and the condion number is not high at all IMO (about 10). So I consider it is not a difficult problem numerically (?).
‘dual-simplex-legacy’ able to find the solution, however not the default algorithm ‘dual-simplex-highs’, the output does not help much what is wrong.
Can someone tell me where I could investigate further to the cause?
load(‘linprog_test.mat’)
size(Aeq)
cond(full(Aeq))
linprogopt = optimset(‘Algorithm’, ‘dual-simplex-legacy’);
[lpsol, ~, exitflag, out] = linprog(c, [], [], Aeq, beq, LB, UB, linprogopt)
linprogopt = optimset(‘Algorithm’, ‘dual-simplex-highs’);
[lpsol, ~, exitflag, out] = linprog(c, [], [], Aeq, beq, LB, UB, linprogopt)I try to see why ‘dual-simplex-highs’ algorithm fails and ‘dual-simplex-legacy’ works OK on this specific LP problem of size 467.
The linear programming involves only linear equality constraints, and lower bounds x >= 0 on some components of x (but not all of them).
The Aeq size is 211 x 467 and the condion number is not high at all IMO (about 10). So I consider it is not a difficult problem numerically (?).
‘dual-simplex-legacy’ able to find the solution, however not the default algorithm ‘dual-simplex-highs’, the output does not help much what is wrong.
Can someone tell me where I could investigate further to the cause?
load(‘linprog_test.mat’)
size(Aeq)
cond(full(Aeq))
linprogopt = optimset(‘Algorithm’, ‘dual-simplex-legacy’);
[lpsol, ~, exitflag, out] = linprog(c, [], [], Aeq, beq, LB, UB, linprogopt)
linprogopt = optimset(‘Algorithm’, ‘dual-simplex-highs’);
[lpsol, ~, exitflag, out] = linprog(c, [], [], Aeq, beq, LB, UB, linprogopt) I try to see why ‘dual-simplex-highs’ algorithm fails and ‘dual-simplex-legacy’ works OK on this specific LP problem of size 467.
The linear programming involves only linear equality constraints, and lower bounds x >= 0 on some components of x (but not all of them).
The Aeq size is 211 x 467 and the condion number is not high at all IMO (about 10). So I consider it is not a difficult problem numerically (?).
‘dual-simplex-legacy’ able to find the solution, however not the default algorithm ‘dual-simplex-highs’, the output does not help much what is wrong.
Can someone tell me where I could investigate further to the cause?
load(‘linprog_test.mat’)
size(Aeq)
cond(full(Aeq))
linprogopt = optimset(‘Algorithm’, ‘dual-simplex-legacy’);
[lpsol, ~, exitflag, out] = linprog(c, [], [], Aeq, beq, LB, UB, linprogopt)
linprogopt = optimset(‘Algorithm’, ‘dual-simplex-highs’);
[lpsol, ~, exitflag, out] = linprog(c, [], [], Aeq, beq, LB, UB, linprogopt) linprog, dual-simplex-highs, failure MATLAB Answers — New Questions
Vectorizing a Simple(?) Operation
Hi all,
This might be a bit of a fruitless question but I just want to confirm there is no other method. I want to know if there is any way of vectorizing the following code:
array = [1,0,1,1,0,0,1];
for i = 2:length(array)-1
if array(i-1) ~= array(i+1)
% Generate a random bit (0 or 1)
random_bit = randi([0, 1]);
% Update the array in place
array(i) = mod(array(i) + random_bit, 2);
end
end
The array can be of any length as long as it is only fillled with 0s and 1s. The key part of the code is that I want to update the array by doing nearest neighbor checks and in such a way that the number of walls (array(i) ~= array(i+1) for i from 1 to size(array)) is constant. And it is this constrained logic of my code that leads me to believe I cannot do away with using for-loops.
The reason I wish to vectorize the code is because I will be doing monte-carlo sampling where I have a large number of these arrays and wish to update them all at the same time using the above update rule, so in the ideal scenario I wouldn’t have to use a nested for-loop to cycle through each sample.Hi all,
This might be a bit of a fruitless question but I just want to confirm there is no other method. I want to know if there is any way of vectorizing the following code:
array = [1,0,1,1,0,0,1];
for i = 2:length(array)-1
if array(i-1) ~= array(i+1)
% Generate a random bit (0 or 1)
random_bit = randi([0, 1]);
% Update the array in place
array(i) = mod(array(i) + random_bit, 2);
end
end
The array can be of any length as long as it is only fillled with 0s and 1s. The key part of the code is that I want to update the array by doing nearest neighbor checks and in such a way that the number of walls (array(i) ~= array(i+1) for i from 1 to size(array)) is constant. And it is this constrained logic of my code that leads me to believe I cannot do away with using for-loops.
The reason I wish to vectorize the code is because I will be doing monte-carlo sampling where I have a large number of these arrays and wish to update them all at the same time using the above update rule, so in the ideal scenario I wouldn’t have to use a nested for-loop to cycle through each sample. Hi all,
This might be a bit of a fruitless question but I just want to confirm there is no other method. I want to know if there is any way of vectorizing the following code:
array = [1,0,1,1,0,0,1];
for i = 2:length(array)-1
if array(i-1) ~= array(i+1)
% Generate a random bit (0 or 1)
random_bit = randi([0, 1]);
% Update the array in place
array(i) = mod(array(i) + random_bit, 2);
end
end
The array can be of any length as long as it is only fillled with 0s and 1s. The key part of the code is that I want to update the array by doing nearest neighbor checks and in such a way that the number of walls (array(i) ~= array(i+1) for i from 1 to size(array)) is constant. And it is this constrained logic of my code that leads me to believe I cannot do away with using for-loops.
The reason I wish to vectorize the code is because I will be doing monte-carlo sampling where I have a large number of these arrays and wish to update them all at the same time using the above update rule, so in the ideal scenario I wouldn’t have to use a nested for-loop to cycle through each sample. vectorization MATLAB Answers — New Questions
Why is 0.3 – 0.2 – 0.1 not equal to zero?
Why does
0.3 – 0.2 – 0.1 == 0
or
v = 0:0.1:1;
any(v == 0.3)
(or similar numbers) reply false?Why does
0.3 – 0.2 – 0.1 == 0
or
v = 0:0.1:1;
any(v == 0.3)
(or similar numbers) reply false? Why does
0.3 – 0.2 – 0.1 == 0
or
v = 0:0.1:1;
any(v == 0.3)
(or similar numbers) reply false? faqlist, floating point, limited precision, faq_fp MATLAB Answers — New Questions
I have the problem of Error Dialog.
I’m trying to open my MATLAB file but it’s doesn’t open. keep on writting this error which I don’t understand because I lasp open my file on the 23/08/24.I’m trying to open my MATLAB file but it’s doesn’t open. keep on writting this error which I don’t understand because I lasp open my file on the 23/08/24. I’m trying to open my MATLAB file but it’s doesn’t open. keep on writting this error which I don’t understand because I lasp open my file on the 23/08/24. error dialog MATLAB Answers — New Questions
Matlab code does not run past a certain point: i.e. buffers at a certain line of code
So I’m trying to solve a problem (attached below) and I’ve written the code (below) to solve it. When I go to run the code it gets stuck at the following line:
% Solve the ODEs numerically
%[t, y] = ode45(odeFunc, [t0, 1.66*3600], [r0; v0], options);
It fully ran once, but continues to not run.
This is the problem:
Code:
G = 6.6742e-11; % universal gravitational constant (km^3/kg/s^2)
M = 5.974e24; % Earth mass estimate (kg)
R = 6378; % planet radius (km)
r0 = [3207 5459 2714]; % initial position vector (km)
v0 = [-6.532 0.7835 6.142]; % initial velocity vector (km/s)
t0 = 0; % initial time in seconds
% Define the ODEs
odeFunc = @(t, y) [y(4); y(5); y(6); -G*M*y(1)/(norm(y(1:3))^3); -G*M*y(2)/(norm(y(1:3))^3); -G*M*y(3)/(norm(y(1:3))^3)];
% Set options for ode45 solver
options = odeset(‘RelTol’, 1e-6, ‘AbsTol’, 1e-6);
% Solve the ODEs numerically
[t, y] = ode45(odeFunc, [t0, 1.66*3600], [r0; v0], options);
% Calculate altitude above Earth’s surface
altitudes = sqrt(sum(y(:, 1:3).^2, 2)) – R;
% Find the maximum altitude and the time at which it occurs
[maxAltitude, maxAltitudeIndex] = max(altitudes);
timeOfMaxAltitude = t(maxAltitudeIndex);
% Display the results
fprintf(‘Maximum Altitude: %.2f kmn’, maxAltitude);
fprintf(‘Time of Maximum Altitude: %.2f hoursn’, timeOfMaxAltitude / 3600);So I’m trying to solve a problem (attached below) and I’ve written the code (below) to solve it. When I go to run the code it gets stuck at the following line:
% Solve the ODEs numerically
%[t, y] = ode45(odeFunc, [t0, 1.66*3600], [r0; v0], options);
It fully ran once, but continues to not run.
This is the problem:
Code:
G = 6.6742e-11; % universal gravitational constant (km^3/kg/s^2)
M = 5.974e24; % Earth mass estimate (kg)
R = 6378; % planet radius (km)
r0 = [3207 5459 2714]; % initial position vector (km)
v0 = [-6.532 0.7835 6.142]; % initial velocity vector (km/s)
t0 = 0; % initial time in seconds
% Define the ODEs
odeFunc = @(t, y) [y(4); y(5); y(6); -G*M*y(1)/(norm(y(1:3))^3); -G*M*y(2)/(norm(y(1:3))^3); -G*M*y(3)/(norm(y(1:3))^3)];
% Set options for ode45 solver
options = odeset(‘RelTol’, 1e-6, ‘AbsTol’, 1e-6);
% Solve the ODEs numerically
[t, y] = ode45(odeFunc, [t0, 1.66*3600], [r0; v0], options);
% Calculate altitude above Earth’s surface
altitudes = sqrt(sum(y(:, 1:3).^2, 2)) – R;
% Find the maximum altitude and the time at which it occurs
[maxAltitude, maxAltitudeIndex] = max(altitudes);
timeOfMaxAltitude = t(maxAltitudeIndex);
% Display the results
fprintf(‘Maximum Altitude: %.2f kmn’, maxAltitude);
fprintf(‘Time of Maximum Altitude: %.2f hoursn’, timeOfMaxAltitude / 3600); So I’m trying to solve a problem (attached below) and I’ve written the code (below) to solve it. When I go to run the code it gets stuck at the following line:
% Solve the ODEs numerically
%[t, y] = ode45(odeFunc, [t0, 1.66*3600], [r0; v0], options);
It fully ran once, but continues to not run.
This is the problem:
Code:
G = 6.6742e-11; % universal gravitational constant (km^3/kg/s^2)
M = 5.974e24; % Earth mass estimate (kg)
R = 6378; % planet radius (km)
r0 = [3207 5459 2714]; % initial position vector (km)
v0 = [-6.532 0.7835 6.142]; % initial velocity vector (km/s)
t0 = 0; % initial time in seconds
% Define the ODEs
odeFunc = @(t, y) [y(4); y(5); y(6); -G*M*y(1)/(norm(y(1:3))^3); -G*M*y(2)/(norm(y(1:3))^3); -G*M*y(3)/(norm(y(1:3))^3)];
% Set options for ode45 solver
options = odeset(‘RelTol’, 1e-6, ‘AbsTol’, 1e-6);
% Solve the ODEs numerically
[t, y] = ode45(odeFunc, [t0, 1.66*3600], [r0; v0], options);
% Calculate altitude above Earth’s surface
altitudes = sqrt(sum(y(:, 1:3).^2, 2)) – R;
% Find the maximum altitude and the time at which it occurs
[maxAltitude, maxAltitudeIndex] = max(altitudes);
timeOfMaxAltitude = t(maxAltitudeIndex);
% Display the results
fprintf(‘Maximum Altitude: %.2f kmn’, maxAltitude);
fprintf(‘Time of Maximum Altitude: %.2f hoursn’, timeOfMaxAltitude / 3600); ode45 MATLAB Answers — New Questions
Can a system() Command be used Inside a Function Called from Inside a parfor Loop?
Is the following code allowed:
result = zeros(100,1);
parfor ii = 1:100
% do something
result(ii) = myfun(resultfromdoingsomething)
end
function result = myfun(inp)
% do something and write a file based on inp
status = system(command); % command executes an executable that reads in the file that was written and produces an output file
result = % read in the file produced by the executable and grab a value to return
% delete the files
end
Even if allowed, are there any risks to be concerned about?
Would also like to know if there are any differences between 2024a and 2019b in this regard.Is the following code allowed:
result = zeros(100,1);
parfor ii = 1:100
% do something
result(ii) = myfun(resultfromdoingsomething)
end
function result = myfun(inp)
% do something and write a file based on inp
status = system(command); % command executes an executable that reads in the file that was written and produces an output file
result = % read in the file produced by the executable and grab a value to return
% delete the files
end
Even if allowed, are there any risks to be concerned about?
Would also like to know if there are any differences between 2024a and 2019b in this regard. Is the following code allowed:
result = zeros(100,1);
parfor ii = 1:100
% do something
result(ii) = myfun(resultfromdoingsomething)
end
function result = myfun(inp)
% do something and write a file based on inp
status = system(command); % command executes an executable that reads in the file that was written and produces an output file
result = % read in the file produced by the executable and grab a value to return
% delete the files
end
Even if allowed, are there any risks to be concerned about?
Would also like to know if there are any differences between 2024a and 2019b in this regard. parfor, system command MATLAB Answers — New Questions
Prediction based on ClassificationPartitionedModel
Hi all,
I have a predictor matrix X and binary response y (1000 observations) and want to use support vector machine (or other machine learning techniques built in Matlab, i.e., fitctree, fitcdiscr, fitcknn, fitcnet) to train the classifier based on 10-fold cross-validation.
My idea is to use 1-999 observations for cross-validation training and testing, and use the best classifier to predict a single out-of-sample y based on 1000th X. How can I do that?
Without cross-validation, I can simply use predict(.) function in Matlab to predict a single y based on 1000th X. However, this is not allowed when cross-validation is used. For a ClassificationPartitionedModel, the function kfoldPredict(.) should be used. The problem is, I am not allowed to specify the X when using kfoldPredict.
Is there anyone know the answer?
Many thanks.Hi all,
I have a predictor matrix X and binary response y (1000 observations) and want to use support vector machine (or other machine learning techniques built in Matlab, i.e., fitctree, fitcdiscr, fitcknn, fitcnet) to train the classifier based on 10-fold cross-validation.
My idea is to use 1-999 observations for cross-validation training and testing, and use the best classifier to predict a single out-of-sample y based on 1000th X. How can I do that?
Without cross-validation, I can simply use predict(.) function in Matlab to predict a single y based on 1000th X. However, this is not allowed when cross-validation is used. For a ClassificationPartitionedModel, the function kfoldPredict(.) should be used. The problem is, I am not allowed to specify the X when using kfoldPredict.
Is there anyone know the answer?
Many thanks. Hi all,
I have a predictor matrix X and binary response y (1000 observations) and want to use support vector machine (or other machine learning techniques built in Matlab, i.e., fitctree, fitcdiscr, fitcknn, fitcnet) to train the classifier based on 10-fold cross-validation.
My idea is to use 1-999 observations for cross-validation training and testing, and use the best classifier to predict a single out-of-sample y based on 1000th X. How can I do that?
Without cross-validation, I can simply use predict(.) function in Matlab to predict a single y based on 1000th X. However, this is not allowed when cross-validation is used. For a ClassificationPartitionedModel, the function kfoldPredict(.) should be used. The problem is, I am not allowed to specify the X when using kfoldPredict.
Is there anyone know the answer?
Many thanks. machine learning, time series, prediction MATLAB Answers — New Questions
What are my license details?
What are my license details?What are my license details? What are my license details? MATLAB Answers — New Questions
Why is the “mjs” file missing from my installation of MATLAB Parallel Server?
Why is the "mjs" file missing from my installation of MATLAB Parallel Server?Why is the "mjs" file missing from my installation of MATLAB Parallel Server? Why is the "mjs" file missing from my installation of MATLAB Parallel Server? MATLAB Answers — New Questions
Why do I get an unhelpful error message when assigning a “struct” only to the end of the last structure array entry initialized by empty brackets?
I am initializing an empty structure array using empty brackets:
>> myStruct(3).myField = [];
Then, all the initialized structure arrays are of type "double":
>> {class(myStruct(1).myField), class(myStruct(2).myField), class(myStruct(3).myField)}
ans =
1×3 cell array
{‘double’} {‘double’} {‘double’}
Why do I get an unhelpful error of "Conversion to double from struct is not possible" only when appending a "struct" to the end of the last array entry?
For example, the following code snippet executes without an error, which changes the class of the first and second entries of "myStruct" to "struct":
>> myStruct(1).myField(2) = struct(‘myVar’, 3);
>> myStruct(2).myField(2) = struct(‘myVar’, 3);
>> {class(myStruct(1).myField), class(myStruct(2).myField), class(myStruct(3).myField)}
ans =
1×3 cell array
{‘struct’} {‘struct’} {‘double’}
However, executing a similar line of code for the last entry of "myStruct" does throw an error:
>> myStruct(3).myField(2) = struct(‘myVar’, 3);
Conversion to double from struct is not possible.I am initializing an empty structure array using empty brackets:
>> myStruct(3).myField = [];
Then, all the initialized structure arrays are of type "double":
>> {class(myStruct(1).myField), class(myStruct(2).myField), class(myStruct(3).myField)}
ans =
1×3 cell array
{‘double’} {‘double’} {‘double’}
Why do I get an unhelpful error of "Conversion to double from struct is not possible" only when appending a "struct" to the end of the last array entry?
For example, the following code snippet executes without an error, which changes the class of the first and second entries of "myStruct" to "struct":
>> myStruct(1).myField(2) = struct(‘myVar’, 3);
>> myStruct(2).myField(2) = struct(‘myVar’, 3);
>> {class(myStruct(1).myField), class(myStruct(2).myField), class(myStruct(3).myField)}
ans =
1×3 cell array
{‘struct’} {‘struct’} {‘double’}
However, executing a similar line of code for the last entry of "myStruct" does throw an error:
>> myStruct(3).myField(2) = struct(‘myVar’, 3);
Conversion to double from struct is not possible. I am initializing an empty structure array using empty brackets:
>> myStruct(3).myField = [];
Then, all the initialized structure arrays are of type "double":
>> {class(myStruct(1).myField), class(myStruct(2).myField), class(myStruct(3).myField)}
ans =
1×3 cell array
{‘double’} {‘double’} {‘double’}
Why do I get an unhelpful error of "Conversion to double from struct is not possible" only when appending a "struct" to the end of the last array entry?
For example, the following code snippet executes without an error, which changes the class of the first and second entries of "myStruct" to "struct":
>> myStruct(1).myField(2) = struct(‘myVar’, 3);
>> myStruct(2).myField(2) = struct(‘myVar’, 3);
>> {class(myStruct(1).myField), class(myStruct(2).myField), class(myStruct(3).myField)}
ans =
1×3 cell array
{‘struct’} {‘struct’} {‘double’}
However, executing a similar line of code for the last entry of "myStruct" does throw an error:
>> myStruct(3).myField(2) = struct(‘myVar’, 3);
Conversion to double from struct is not possible. structinitialization MATLAB Answers — New Questions
Flipping a matrix diagonally
I would like to flip a matrix that I have diagonally from left to right as shown in the image. Is there a command or a simple way to do this? The other two ends of my matrices have the correct values so I do not want them to moveI would like to flip a matrix that I have diagonally from left to right as shown in the image. Is there a command or a simple way to do this? The other two ends of my matrices have the correct values so I do not want them to move I would like to flip a matrix that I have diagonally from left to right as shown in the image. Is there a command or a simple way to do this? The other two ends of my matrices have the correct values so I do not want them to move flip, matrix manipulation, matrix MATLAB Answers — New Questions
How to replace values in a table with the outputs of another code?
I am attempting to create a table that will display the results gotten from running through another MATLAB code however I just cannot seem to replace the values in the table with the new values.
I have the Table labeled so that I can output it but I don’t understand why I can’t replace the Table values (that I have currently stored as 0’s) with the outputs. I got and error originally saying that the right hand side needed to be a table or an array (Originally i just had the "minPModel" and such but since replaced them with the new table "MinMaxTab" and it still won’t accept it). I don’t understand how to get it to work.
Attached is the MinMax file
Table1 = table([0.50; 0.75; 1; 1.25; 1.5; 1.75; 2],…
[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],…
‘VariableNames’,{‘R (mmHg*s/ml)’ ‘Pressure Maximum (mmHg)’ ‘Pressure Minimum (mmHg)’ ‘Presure Mean (mmHg)’ ‘Pulse Pressure (max-min) (mmHg)’});
for R = 0.5:.25:2
k = 2;
fprintf("R = %d", R);
run MinMax.m;
MinMaxTab = [minPModel; maxPModel; meanPModel];
Table1(2,k) = MinMaxTab(1,1);
Table1(3,k) = MinMaxTab(1,2);
Table1(4,k) = MinMaxTab(1,3);
Table1(5,k) = Table1(3,k)-Table1(2,k);
k=k+1;
end
Table1I am attempting to create a table that will display the results gotten from running through another MATLAB code however I just cannot seem to replace the values in the table with the new values.
I have the Table labeled so that I can output it but I don’t understand why I can’t replace the Table values (that I have currently stored as 0’s) with the outputs. I got and error originally saying that the right hand side needed to be a table or an array (Originally i just had the "minPModel" and such but since replaced them with the new table "MinMaxTab" and it still won’t accept it). I don’t understand how to get it to work.
Attached is the MinMax file
Table1 = table([0.50; 0.75; 1; 1.25; 1.5; 1.75; 2],…
[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],…
‘VariableNames’,{‘R (mmHg*s/ml)’ ‘Pressure Maximum (mmHg)’ ‘Pressure Minimum (mmHg)’ ‘Presure Mean (mmHg)’ ‘Pulse Pressure (max-min) (mmHg)’});
for R = 0.5:.25:2
k = 2;
fprintf("R = %d", R);
run MinMax.m;
MinMaxTab = [minPModel; maxPModel; meanPModel];
Table1(2,k) = MinMaxTab(1,1);
Table1(3,k) = MinMaxTab(1,2);
Table1(4,k) = MinMaxTab(1,3);
Table1(5,k) = Table1(3,k)-Table1(2,k);
k=k+1;
end
Table1 I am attempting to create a table that will display the results gotten from running through another MATLAB code however I just cannot seem to replace the values in the table with the new values.
I have the Table labeled so that I can output it but I don’t understand why I can’t replace the Table values (that I have currently stored as 0’s) with the outputs. I got and error originally saying that the right hand side needed to be a table or an array (Originally i just had the "minPModel" and such but since replaced them with the new table "MinMaxTab" and it still won’t accept it). I don’t understand how to get it to work.
Attached is the MinMax file
Table1 = table([0.50; 0.75; 1; 1.25; 1.5; 1.75; 2],…
[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],…
‘VariableNames’,{‘R (mmHg*s/ml)’ ‘Pressure Maximum (mmHg)’ ‘Pressure Minimum (mmHg)’ ‘Presure Mean (mmHg)’ ‘Pulse Pressure (max-min) (mmHg)’});
for R = 0.5:.25:2
k = 2;
fprintf("R = %d", R);
run MinMax.m;
MinMaxTab = [minPModel; maxPModel; meanPModel];
Table1(2,k) = MinMaxTab(1,1);
Table1(3,k) = MinMaxTab(1,2);
Table1(4,k) = MinMaxTab(1,3);
Table1(5,k) = Table1(3,k)-Table1(2,k);
k=k+1;
end
Table1 table, replacement, optimization MATLAB Answers — New Questions
Two Arduinos with Two Simulink Model
Hi,
Please let me know if I am doing something wrong or it is just the limit of Matlab.
I have 2 Arduinos, Uno and Due.
I created two different Simulink model that 1, Uno, is going to be the output as sending digital signal. The second model is going to be the Due as an input to read what is on the pin.
When I open them both, set the Hardware, set the comport, and ran. Only one of them runs not the other.
Once one of them runs then the another Simulink model thinks that it needs to be connected to the currently connected device.
For example, if I run the Uno model, then the Simulink model (A) connects to Uno successfully. However, while the Due is connected, run the Due Simulink model (B) then it shows me an error saying that sorry I can’t connect to Uno. I told the Simulink to connect to Due at a specific port but it is keep doing this.
Has anyone have experience in setting two arduinos and two simulink model separatly?
Thanks!Hi,
Please let me know if I am doing something wrong or it is just the limit of Matlab.
I have 2 Arduinos, Uno and Due.
I created two different Simulink model that 1, Uno, is going to be the output as sending digital signal. The second model is going to be the Due as an input to read what is on the pin.
When I open them both, set the Hardware, set the comport, and ran. Only one of them runs not the other.
Once one of them runs then the another Simulink model thinks that it needs to be connected to the currently connected device.
For example, if I run the Uno model, then the Simulink model (A) connects to Uno successfully. However, while the Due is connected, run the Due Simulink model (B) then it shows me an error saying that sorry I can’t connect to Uno. I told the Simulink to connect to Due at a specific port but it is keep doing this.
Has anyone have experience in setting two arduinos and two simulink model separatly?
Thanks! Hi,
Please let me know if I am doing something wrong or it is just the limit of Matlab.
I have 2 Arduinos, Uno and Due.
I created two different Simulink model that 1, Uno, is going to be the output as sending digital signal. The second model is going to be the Due as an input to read what is on the pin.
When I open them both, set the Hardware, set the comport, and ran. Only one of them runs not the other.
Once one of them runs then the another Simulink model thinks that it needs to be connected to the currently connected device.
For example, if I run the Uno model, then the Simulink model (A) connects to Uno successfully. However, while the Due is connected, run the Due Simulink model (B) then it shows me an error saying that sorry I can’t connect to Uno. I told the Simulink to connect to Due at a specific port but it is keep doing this.
Has anyone have experience in setting two arduinos and two simulink model separatly?
Thanks! arduino, simulink, embedded coder, matlab MATLAB Answers — New Questions
How to resize axes programmatically within a GUI built with uifigure and uigridlayout?
Hi everyone,
I’ve been building a GUI based on a uifigure and the matlab.apps.AppBase tools. It’s not built in App Designer, I do it programmatically. I use a uigridlayout to position my various items; it works quite well for most things, but I’m having trouble with uiaxes.
These uiaxes are located within the uigridlayout, but I need to make a slight size adjustment after they’ve been created. I just need to adjust the width, I know by how many pixels to adjust it. If I run my app by typing "app = appName();" in the command window, the app shows up, the uiaxes are not adjusted. I then issue the command in the command window: "app.myAxes.Position(3) = app.myAxes.Position(3) – boxWidth;", which does exactly what I need it to do.
However, adding that line of code in the code that builds the actual GUI does not work, no matter where I try to put it. I’ve set AutoResizeChildren of the uifigure to off, no luck. I’ve searched here, but nothing I found seems to work.
So how do I get my app to execute that particular line of code?
Cheers,
ChristianeHi everyone,
I’ve been building a GUI based on a uifigure and the matlab.apps.AppBase tools. It’s not built in App Designer, I do it programmatically. I use a uigridlayout to position my various items; it works quite well for most things, but I’m having trouble with uiaxes.
These uiaxes are located within the uigridlayout, but I need to make a slight size adjustment after they’ve been created. I just need to adjust the width, I know by how many pixels to adjust it. If I run my app by typing "app = appName();" in the command window, the app shows up, the uiaxes are not adjusted. I then issue the command in the command window: "app.myAxes.Position(3) = app.myAxes.Position(3) – boxWidth;", which does exactly what I need it to do.
However, adding that line of code in the code that builds the actual GUI does not work, no matter where I try to put it. I’ve set AutoResizeChildren of the uifigure to off, no luck. I’ve searched here, but nothing I found seems to work.
So how do I get my app to execute that particular line of code?
Cheers,
Christiane Hi everyone,
I’ve been building a GUI based on a uifigure and the matlab.apps.AppBase tools. It’s not built in App Designer, I do it programmatically. I use a uigridlayout to position my various items; it works quite well for most things, but I’m having trouble with uiaxes.
These uiaxes are located within the uigridlayout, but I need to make a slight size adjustment after they’ve been created. I just need to adjust the width, I know by how many pixels to adjust it. If I run my app by typing "app = appName();" in the command window, the app shows up, the uiaxes are not adjusted. I then issue the command in the command window: "app.myAxes.Position(3) = app.myAxes.Position(3) – boxWidth;", which does exactly what I need it to do.
However, adding that line of code in the code that builds the actual GUI does not work, no matter where I try to put it. I’ve set AutoResizeChildren of the uifigure to off, no luck. I’ve searched here, but nothing I found seems to work.
So how do I get my app to execute that particular line of code?
Cheers,
Christiane uiaxes uigridlayout MATLAB Answers — New Questions