現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
How to solve "Attempted to access index 0 of an array with smaller dimension sizes.
18 ビュー (過去 30 日間)
古いコメントを表示
I'm trying to compare current data with previous data like data(i)-data(i-1) in simulink. 'b' is the input from workspace where i had transfer the data from excel. When i run the simulink the error as stated in the title occured. Anyone here know how to solve?
function [y,z]= fcn(b)
% b=current input PV power,
%y= power fluctuation, z=smoothed output
for i = 1:1440;
y = (b(i))-(b(i-1))/6240*100;
if (y>10)
z = b(i-1) - [(abs(y-10))*6240/100];
elseif (y<-10)
z=b(i-1) + [(abs(y+10))*6240/100];
else
z = b(i);
end
end
回答 (1 件)
Mehmed Saad
2020 年 4 月 18 日
編集済み: Mehmed Saad
2020 年 4 月 18 日
function [y,z]= fcn(b)
% b=current input PV power,
%y= power fluctuation, z=smoothed output
for i = 2:length(b);
y = (b(i))-(b(i-1))/6240*100;
if (y>10)
z = b(i-1) - [(abs(y-10))*6240/100];
elseif (y<-10)
z=b(i-1) + [(abs(y+10))*6240/100];
else
z = b(i);
end
end
25 件のコメント
Kenneth Yee
2020 年 4 月 18 日
After I changed the i=1:1440 to i=2:1440, error occured as "Attempted to access index 2 of an array with smaller dimension sizes." I had tried this before, no matter what value i change in 'i', it shows in the error again
Mehmed Saad
2020 年 4 月 18 日
編集済み: Mehmed Saad
2020 年 4 月 18 日
see the updae
for i = 2:length(b)
also it seems like b is not an array in your code
according to logic b should ve length of 1440
Kenneth Yee
2020 年 4 月 18 日
An error shows like this "Simulink does not have enough information to determine output sizes for this block. If you think the errors below are inaccurate, try specifying types for the block inputs and/or sizes for the block outputs." after i tried for i = 2:length(b)
Yes, my data has two coloumn , 1st column is no. from 1 to 1440, 2nd coloumn is the value i want to compare
Mehmed Saad
2020 年 4 月 18 日
In case if b is a variable i..e only 1 value come out of it then the function should be
function [y,z]= fcn(b,b0)
% b=current input PV power,
y = (b-b0)/6240*100;
if (y>10)
z = b0 - [(abs(y-10))*6240/100];
elseif (y<-10)
z=b0 + [(abs(y+10))*6240/100];
else
z = b;
end
end
and the block should be like
i.e. add a delay
Kenneth Yee
2020 年 4 月 18 日
Based on the idea u give, the output is not what i wanted. Here is the simulink file.
Mehmed Saad
2020 年 4 月 18 日
Run this code before runing simulink model
T=readmatrix('PvPower.xlsx');
t = T(:,1);
x = T(:,2);
so that variable x and t are in your workspace
Changes i ve made are following
- time and data from workspace
- adding delay
- Changing the function for step by step process
function [y,z]= fcn(b,b0)
% b=current input PV power,
%y= power fluctuation, z=smoothed output
y = (b-b0)/6240*100;
if (y>10)
z = b0 - (abs(y-10))*6240/100;
elseif (y<-10)
z=b0 + (abs(y+10))*6240/100;
else
z = b;
end
end
Kenneth Yee
2020 年 4 月 18 日
The variable x and t is not in my workspace after i followed what you mentioned up there.
Mehmed Saad
2020 年 4 月 18 日
Run this script first in matlab, so that x and t are in your workspace
T=readmatrix('PvPower.xlsx');
t = T(:,1);
x = T(:,2);
R2016a version is attached
Kenneth Yee
2020 年 4 月 18 日
I had run the script in matlab and it show
"Error in Untitled (line 1)
T=readmatrix('PvPower.xlsx');"
and i dont know why
Mehmed Saad
2020 年 4 月 18 日
編集済み: Mehmed Saad
2020 年 4 月 18 日
filename = 'complete path of your excel file you want to read along with filename';
T=readmatrix(filename);
Kenneth Yee
2020 年 4 月 18 日
Yes i understand, where you save your excel file in? I save in D disk and the script save in disk D also cannot , still got error
Mehmed Saad
2020 年 4 月 18 日
編集済み: Mehmed Saad
2020 年 4 月 18 日
Error was occuring maybe because readmatrix was not in R2016a, instead of that we use xlsread
step-1: Run this code in matlab script and select your excel file
[file_n,folder_n] = uigetfile('*.xlsx');
filename = strcat(folder_n,file_n);
T=xlsread(filename);
t = T(:,1);
x = T(:,2);
Kenneth Yee
2020 年 4 月 18 日
Hi, i run the code as
[file_n,folder_n] = uigetfile('PvPower.xlsx');
'PvPower.xlsx' = strcat(folder_n,file_n);
T=readmatrix('PvPower.xlsx');
t = T(:,1);
x = T(:,2);
There is an error,
Error: File: data.m Line: 2 Column: 16
The expression to the left of the equals sign is not a valid target for an assignment.
is my script wrong? The file and folder indicate?
Mehmed Saad
2020 年 4 月 18 日
Run this only, donot edit anything, it will open a window explorer infront of you, Now select the excel file you want to open
[file_n,folder_n] = uigetfile('*.xlsx');
filename = strcat(folder_n,file_n);
T=xlsread(filename);
t = T(:,1);
x = T(:,2);
Kenneth Yee
2020 年 4 月 18 日
Yes, i did it.
After i run the simulink, the error occur as
The sample time propagated to 'PvPower2016b/Delay' is not discrete but [0, 1]. Specify a discrete sample time in the source of the incoming signal.
May i know how you setting the delay block?
Kenneth Yee
2020 年 4 月 19 日
I had tried it at 2020 version and the output is not i wanted. I will try to figure why. Thank you for your info.
Mehmed Saad
2020 年 4 月 19 日
編集済み: Mehmed Saad
2020 年 4 月 19 日
Choose sampling time, sorry i forgot to change that, try the new one
Kenneth Yee
2020 年 4 月 19 日
Yes, I had insert the excel data before run the simulink. Just the data after going through delay block is not what i wanted then the whole output become incorrect. As I thought, the delay block will just delay the input data one time step but its not.
Kenneth Yee
2020 年 4 月 19 日
I had tried the latest one. What i want from the delay block is delay one time step compare to the original data, but what i get from the delay block is advance one time step. The data i want, for example, the original data at 694th is 4607.79, the data i want to get after the delay block at 693th is 4607.79.
You understand what i mean?
参考
カテゴリ
Help Center および File Exchange で Programmatic Model Editing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)