load function not returning correct array dimension

조회 수: 1 (최근 30일)
Muhammad Safwan Razif
Muhammad Safwan Razif 2022년 6월 27일
댓글: Muhammad Safwan Razif 2022년 6월 27일
So I want to save() a bunch of array in another file so i can acces it later using load(). When i want to use the array(12x18), i got error message, "error: reshape: can't reshape 1x1 array to 6x3 array". Below is an example of how my code is. How do properly store and access the matrix ? I use a lot of reshape in my code.
a = randi(12,12,18);
save('a.mat','a');
b = load('a.mat','a')
c = reshape(b(1,:),[6,3])
  댓글 수: 2
Johan
Johan 2022년 6월 27일
load puts your saved data in a structure, use b.a to access your data
a = randi(12,12,18);
save('a.mat','a');
b = load('a.mat','a')
b = struct with fields:
a: [12×18 double]
c = reshape(b.a(1,:),[6,3])
c = 6×3
6 11 10 8 10 11 9 4 2 11 10 3 8 6 8 3 7 12
Muhammad Safwan Razif
Muhammad Safwan Razif 2022년 6월 27일
Thank you very much sir. That solved my problem :)

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by