How do I get these matrix dimensions to match using linspace?
    조회 수: 3 (최근 30일)
  
       이전 댓글 표시
    
I am trying to write an audio algorithm to ramp up the amplitude of a .wav file but I am having problems getting getting the matrix dimensions to match in this line:
    processed_waveform = input_waveform.*linspace(0, 1, length(input_waveform));
The error reads as follows:
Error using  .* 
Matrix dimensions must agree.
Error in Ex_1D (line 41)
        processed_waveform = input_waveform.*linspace(0, 1, length(input_waveform));
I have tried using size() in place of length() but I still get the same issue. Any ideas? Thanks
댓글 수: 0
채택된 답변
  Star Strider
      
      
 2015년 10월 18일
        Most audio files are column vectors, and linspace produces a row vector.
Try this:
processed_waveform = input_waveform.*linspace(0, 1, length(input_waveform))';
Transposing the linspace vector should make them compatible. If ‘input_waveform’ is a two-column matrix (two-channel sound file), the code becomes:
processed_waveform = input_waveform.*[linspace(0, 1, length(input_waveform))', linspace(0, 1, length(input_waveform))'];
댓글 수: 2
  dpb
      
      
 2015년 10월 18일
				I've long thought (and made the suggestion at least once as enhancement request) TMW should enhance this error message to explicitly note the orientation mismatch as a possbility when size(OP1)==size(OP2).' as the error occurs so often and the present missive, while correct, clearly doesn't provide guidance enough in many (most?) cases...
  Star Strider
      
      
 2015년 10월 18일
				Allowing a size argument that would automatically orient and replicate the resulting vector would be helpful, but we’re not there yet.
추가 답변 (0개)
참고 항목
카테고리
				Help Center 및 File Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기
			
	제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


