이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
How to solve "Attempted to access index 0 of an array with smaller dimension sizes.
조회 수: 14 (최근 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!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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 (한국어)