I am new to MATLAB. I am trying to create a simple program to find and display the risetime of pulse data in a .csv file. The program works for some files but not for other
    조회 수: 2 (최근 30일)
  
       이전 댓글 표시
    
I need to find the value and display a plot of the risetime for the data in a .csv file. The program works for some files but not for others. I get the error message shown below.
I get this error message when I run it:
Unable to perform assignment because the left and right sides have a different number of elements.
Error in Diff_Mode_Voltage_1kVPlot_BFP_NEW1_7_21 (line 256)
Full(i)=risetime(xr,fs,'PercentReferenceLevels',[10 90]);% %'s of levels
Below is the program. Plwase tell me why I get the error.  
227  %RISE TIME---calculate the rise time of the waveform "(TestWaveform 1.csv')"
228   filename1='TestWaveform 1.csv";% reads the csv file as "file1"
229   opts = detectImportOptions(file1);
230   preview(file1,opts)
231   M1 = readmatrix(file1,'Range','D:E');% time is column D and the data value id in column E 
232
233   [C,ia] = unique(M1(:,1));%unique fnction returns the data that is passed but removes all values that is repeated
234   M1 = M1(ia,:);
235
236   RT=risetime(M1(:,2),M1(:,1));% Names the rise time RT
237
238    for k = 1:2
239    RT= risetime(M1(:,2), M1(:,1));
240    [W,INITCROSS,FINALCROSS,MIDLEV] = pulsewidth(M1(:,2), M1(:,1));% do I need this???
241   PW{k,:} = {W,INITCROSS,FINALCROSS,MIDLEV};% do I need this???
242   end
243
244
245  %Measure/ calculate the rise time at the 10 to 90% points
246   Mylist1 = ls('CSV Files');%gives a list of all contents in the folder. This table can be displayed by entering "Rise" in the command window
247   newList1 = Mylist1(3:end,:);
248   Full = zeros(length(newList1(:,1)),1);%% do I need this???
249   for i = 1:length(newList1(:,1))
250   filename1 = convertCharsToStrings(newList1(i,:));
251   M1 = readmatrix(filename1,'Range','D:E');% M1 is used for rise time
252   tr=M1(:,1);% NOTE, tr is used in rise time
253   xr=M1(:,2);% NOTE, xr is used in rise time
254   fs = 1/(tr(2)-tr(1));
255   Full(i)=risetime(xr,fs,'PercentReferenceLevels',[10 90]);% %'s of levels
256   end
257   
258   %%Calculate and plot the open circuit rise time
259   filename1 = convertCharsToStrings(newList1(9,:));%(9,:) tells the code which csv file in the "newList" folder to use
260   M1 = readmatrix(filename1,'Range','D:E');
261   tr=M1(:,1);
262   xr=M1(:,2);
263   figure%  create a figure for the rist time plot
264   risetime(xr,tr);
265  axis([-0.3e-7, -.1e-7, 0, 7e4])% set the x min/max and y min/max in this order. Note: the Y azis will not plot below 0
266   saveas (gcf, 'plot_10.jpg') %save the plot to a file as "plot_10"
댓글 수: 3
  dpb
      
      
 2021년 7월 23일
				I've not used risetime extensively (it wasn't introduced while I was still in the active consulting gig or would have a lot), but I'd guess the problem is the failing files have more than one discernible bilevel signal transition based on the internal discretization done to set the high and low threshold levels.
If this were true, then there's only one index position availablel on the LHS which is a mismatch in length with the RHS.
Here's an example with a local array just happen to have and an arbitrary assignment of more than one value --
>> A(1)=[4 5];
Unable to perform assignment because the left and right sides have a different number of elements. 
>> 
Look familiar?? :)
  dpb
      
      
 2021년 7월 23일
				Set a breakpoint @Line 255 and then execute the risetime call from  command window and see what is returned.  
To fix, either save the results as a cell array that can handle the variable number that can be returned or preprocess the signal to be sure there's only two discrete levels so only one transition will be located.
답변 (1개)
  BP
 2021년 7월 24일
        댓글 수: 2
  dpb
      
      
 2021년 7월 24일
				
      편집: dpb
      
      
 2021년 7월 24일
  
			Of course you still get the same error, the point was to "Set a breakpoint @Line 255 and then execute the risetime call from  command window and see what is returned."
When debugber halts, then what is the result in the command line of
risetime(xr,fs,'PercentReferenceLevels',[10 90])
???
That will show you what MATLAB is trying to store into the array location Full(i).  It's going to be more than one value as the previous example code showed what generates the error message.
Show us the result of the above to prove it...
PS.  Edit the code in the original Q? would be more better; use the code-edit buttons to do so...
  dpb
      
      
 2021년 7월 24일
				How to fix depends upon what you want the results to be -- if only want/expect one value, then the problem lies in the input data and need to investigate why those files don't match the assumption of there being only one transition located.
Or, if there can be multiple (two or more) and those are ok, then you'll need to use a cell array instead for Full in order to be able to put more numbers than one into each cell.  To do that "use the curlies, Luke" -- either on the LHS around the index or around the RHS expression to cast it to a cell.  Then, the original allocation should be 
Full = cell(numel(newList1),1);
참고 항목
카테고리
				Help Center 및 File Exchange에서 Modulation에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!